refactor: clean code

@TheDevYellowy  :))
This commit is contained in:
March 7th 2022-08-03 19:08:32 +07:00
parent 3bcf936636
commit 196c03f8cc
3 changed files with 21 additions and 19 deletions

View File

@ -1431,7 +1431,7 @@ class Guild extends AnonymousGuild {
/** /**
* Marks the guild as read * Marks the guild as read
* @returns {undefined} nothing :) * @returns {Promise<void>} nothing :)
* @example * @example
* const guild = client.guilds.fetch('222078108977594368'); * const guild = client.guilds.fetch('222078108977594368');
* guild.read(); * guild.read();

View File

@ -2,6 +2,7 @@
const process = require('node:process'); const process = require('node:process');
const { ClientApplicationAssetTypes, Endpoints } = require('../../util/Constants'); const { ClientApplicationAssetTypes, Endpoints } = require('../../util/Constants');
const Permissions = require('../../util/Permissions');
const SnowflakeUtil = require('../../util/SnowflakeUtil'); const SnowflakeUtil = require('../../util/SnowflakeUtil');
const Base = require('../Base'); const Base = require('../Base');
@ -77,29 +78,30 @@ class Application extends Base {
/** /**
* Invites this application to a guild / server * Invites this application to a guild / server
* @param {string} guild_id The id of the guild that you want to invite the bot to * @param {Snowflake} guild_id The id of the guild that you want to invite the bot to
* @param {bigint} [permissions] The permissions for the bot in number form (the default is 8 / Administrator) * @param {PermissionResolvable} [permissions] The permissions for the bot in number form (the default is 8 / Administrator)
* @param {string} [captcha] The captcha key to add * @param {string} [captcha] The captcha key to add
* @returns {undefined} nothing :) * @returns {Promise<void>} nothing :)
*/ */
async invite(guild_id, permissions = 8, captcha = null) { async invite(guild_id, permissions = 0n, captcha = null) {
permissions = Permissions.resolve(permissions);
const postData = {
authorize: true,
guild_id,
permissions: '0',
};
if (permissions) {
postData.permissions = permissions;
}
if (captcha && typeof captcha === 'string' && captcha.length > 0) {
postData.captcha = captcha;
}
await this.client.api.oauth2.authorize.post({ await this.client.api.oauth2.authorize.post({
query: { query: {
client_id: this.id, client_id: this.id,
scope: 'bot applications.commands', scope: 'bot applications.commands',
}, },
data: captcha data: postData,
? {
captcha_key: captcha,
authorize: true,
guild_id,
permissions,
}
: {
authorize: true,
guild_id,
permissions,
},
headers: { headers: {
referer: `https://discord.com/oauth2/authorize?client_id=${this.id}&permissions=${permissions}&scope=bot`, referer: `https://discord.com/oauth2/authorize?client_id=${this.id}&permissions=${permissions}&scope=bot`,
}, },

4
typings/index.d.ts vendored
View File

@ -337,7 +337,7 @@ export abstract class Application extends Base {
public coverURL(options?: StaticImageURLOptions): string | null; public coverURL(options?: StaticImageURLOptions): string | null;
/** @deprecated This method is deprecated as it is unsupported and will be removed in the next major version. */ /** @deprecated This method is deprecated as it is unsupported and will be removed in the next major version. */
public fetchAssets(): Promise<ApplicationAsset[]>; public fetchAssets(): Promise<ApplicationAsset[]>;
public invite(guildID: string, permissions: bigint, captcha: string): null; public invite(guildID: Snowflake, permissions?: PermissionResolvable, captcha?: string): Promise<undefined>;
public iconURL(options?: StaticImageURLOptions): string | null; public iconURL(options?: StaticImageURLOptions): string | null;
public toJSON(): unknown; public toJSON(): unknown;
public toString(): string | null; public toString(): string | null;
@ -1236,7 +1236,7 @@ export class Guild extends AnonymousGuild {
public readonly maximumBitrate: number; public readonly maximumBitrate: number;
public createTemplate(name: string, description?: string): Promise<GuildTemplate>; public createTemplate(name: string, description?: string): Promise<GuildTemplate>;
public delete(): Promise<Guild>; public delete(): Promise<Guild>;
public read(): undefined; public read(): Promise<undefined>;
public discoverySplashURL(options?: StaticImageURLOptions): string | null; public discoverySplashURL(options?: StaticImageURLOptions): string | null;
public edit(data: GuildEditData, reason?: string): Promise<Guild>; public edit(data: GuildEditData, reason?: string): Promise<Guild>;
public editWelcomeScreen(data: WelcomeScreenEditData): Promise<WelcomeScreen>; public editWelcomeScreen(data: WelcomeScreenEditData): Promise<WelcomeScreen>;