From f95436f44bbff8dfcb9d44f7209c3ba321ddb965 Mon Sep 17 00:00:00 2001 From: TheDevYellowy Date: Sat, 30 Jul 2022 05:22:31 -0500 Subject: [PATCH 1/6] bot inviting is somewhat working --- src/structures/ClientApplication.js | 24 ++++++++++++++++++++++++ typings/index.d.ts | 1 + 2 files changed, 25 insertions(+) diff --git a/src/structures/ClientApplication.js b/src/structures/ClientApplication.js index 0abb80f..12bd1e5 100644 --- a/src/structures/ClientApplication.js +++ b/src/structures/ClientApplication.js @@ -142,6 +142,30 @@ class ClientApplication extends Application { this._patch(app.application); return this; } + + /** + * Invites this application to a guild / server + * @param {string} guildID The id of the guild that you want to invite the bot to + * @param {number} permissions The permissions for the bot in number form + * @returns {Promise} + */ + async invite(guildID, permissions = 8) { + let res = await this.client.api.oauth2.authorize.post({ + query: { + client_id: this.id, + scope: 'bot applications.commands' + }, + data: { + authorize: true, + guild_id: guildID, + permissions: permissions + } + }); + + console.log(res) + + return this; + } } module.exports = ClientApplication; diff --git a/typings/index.d.ts b/typings/index.d.ts index ae5edcd..afb00a2 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -874,6 +874,7 @@ export class ClientApplication extends Application { public readonly partial: boolean; public rpcOrigins: string[]; public fetch(): Promise; + public invite(guildID: string, permissions: number): Promise; } export class ClientPresence extends Presence { From 1f587eff99b871961814885a82e50a002b6d5473 Mon Sep 17 00:00:00 2001 From: TheDevYellowy Date: Sun, 31 Jul 2022 00:42:51 -0500 Subject: [PATCH 2/6] move the invite function to Application --- src/structures/ClientApplication.js | 24 ------------------------ src/structures/interfaces/Application.js | 24 ++++++++++++++++++++++++ typings/index.d.ts | 2 +- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/structures/ClientApplication.js b/src/structures/ClientApplication.js index 12bd1e5..0abb80f 100644 --- a/src/structures/ClientApplication.js +++ b/src/structures/ClientApplication.js @@ -142,30 +142,6 @@ class ClientApplication extends Application { this._patch(app.application); return this; } - - /** - * Invites this application to a guild / server - * @param {string} guildID The id of the guild that you want to invite the bot to - * @param {number} permissions The permissions for the bot in number form - * @returns {Promise} - */ - async invite(guildID, permissions = 8) { - let res = await this.client.api.oauth2.authorize.post({ - query: { - client_id: this.id, - scope: 'bot applications.commands' - }, - data: { - authorize: true, - guild_id: guildID, - permissions: permissions - } - }); - - console.log(res) - - return this; - } } module.exports = ClientApplication; diff --git a/src/structures/interfaces/Application.js b/src/structures/interfaces/Application.js index 2334bda..eb9d727 100644 --- a/src/structures/interfaces/Application.js +++ b/src/structures/interfaces/Application.js @@ -75,6 +75,30 @@ class Application extends Base { return new Date(this.createdTimestamp); } + /** + * 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 {number} permissions The permissions for the bot in number form + * @returns nothing :) + */ + async invite(guild_id, permissions = 8) { + let res = await this.client.api.oauth2.authorize.post({ + query: { + client_id: this.id, + scope: 'bot applications.commands' + }, + data: { + authorize: true, + guild_id, + permissions, + } + }); + + console.log(res) + + return; + } + /** * A link to the application's icon. * @param {StaticImageURLOptions} [options={}] Options for the Image URL diff --git a/typings/index.d.ts b/typings/index.d.ts index afb00a2..3b90fc9 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -337,6 +337,7 @@ export abstract class Application extends Base { public coverURL(options?: StaticImageURLOptions): string | null; /** @deprecated This method is deprecated as it is unsupported and will be removed in the next major version. */ public fetchAssets(): Promise; + public invite(guildID: string, permissions: number): Promise; public iconURL(options?: StaticImageURLOptions): string | null; public toJSON(): unknown; public toString(): string | null; @@ -874,7 +875,6 @@ export class ClientApplication extends Application { public readonly partial: boolean; public rpcOrigins: string[]; public fetch(): Promise; - public invite(guildID: string, permissions: number): Promise; } export class ClientPresence extends Presence { From 8bccb552dba21a12358e53b91b50879f675b1077 Mon Sep 17 00:00:00 2001 From: TheDevYellowy Date: Mon, 1 Aug 2022 09:55:30 -0500 Subject: [PATCH 3/6] it works but we may need a captcha key --- src/structures/interfaces/Application.js | 15 ++++++++++++--- typings/index.d.ts | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/structures/interfaces/Application.js b/src/structures/interfaces/Application.js index eb9d727..d68b7c9 100644 --- a/src/structures/interfaces/Application.js +++ b/src/structures/interfaces/Application.js @@ -78,19 +78,28 @@ class Application extends Base { /** * 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 {number} permissions The permissions for the bot in number form + * @param {number} [permissions] The permissions for the bot in number form (the default is 8 / Administrator) + * @param {string} [captcha] The captcha key to add * @returns nothing :) */ - async invite(guild_id, permissions = 8) { + async invite(guild_id, permissions = 8, captcha = null) { let res = await this.client.api.oauth2.authorize.post({ query: { client_id: this.id, scope: 'bot applications.commands' }, - data: { + data: captcha ? { + captcha_key: captcha, authorize: true, guild_id, permissions, + } : { + authorize: true, + guild_id, + permissions, + }, + headers: { + "referer": `https://discord.com/oauth2/authorize?client_id=${this.id}&permissions=${permissions}&scope=bot` } }); diff --git a/typings/index.d.ts b/typings/index.d.ts index 3b90fc9..59188f4 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -337,7 +337,7 @@ export abstract class Application extends Base { public coverURL(options?: StaticImageURLOptions): string | null; /** @deprecated This method is deprecated as it is unsupported and will be removed in the next major version. */ public fetchAssets(): Promise; - public invite(guildID: string, permissions: number): Promise; + public invite(guildID: string, permissions: number, captcha: string): Promise; public iconURL(options?: StaticImageURLOptions): string | null; public toJSON(): unknown; public toString(): string | null; From c9d9b3cf7fe99cc7f18598b559c06c1a2da7dcb7 Mon Sep 17 00:00:00 2001 From: TheDevYellowy Date: Mon, 1 Aug 2022 09:57:19 -0500 Subject: [PATCH 4/6] remove dev stuff --- src/structures/interfaces/Application.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/structures/interfaces/Application.js b/src/structures/interfaces/Application.js index d68b7c9..c45f24a 100644 --- a/src/structures/interfaces/Application.js +++ b/src/structures/interfaces/Application.js @@ -103,8 +103,6 @@ class Application extends Base { } }); - console.log(res) - return; } From 6028e2a63df226f5aaf9651f2ec13459ae0fbcf8 Mon Sep 17 00:00:00 2001 From: TheDevYellowy Date: Mon, 1 Aug 2022 09:57:56 -0500 Subject: [PATCH 5/6] change returns to null --- typings/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index 9a7bb8e..5e2f8ca 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -337,7 +337,7 @@ export abstract class Application extends Base { public coverURL(options?: StaticImageURLOptions): string | null; /** @deprecated This method is deprecated as it is unsupported and will be removed in the next major version. */ public fetchAssets(): Promise; - public invite(guildID: string, permissions: number, captcha: string): Promise; + public invite(guildID: string, permissions: number, captcha: string): null; public iconURL(options?: StaticImageURLOptions): string | null; public toJSON(): unknown; public toString(): string | null; From 8fc282f2ebb87c81b0619e202f807a4c476486ba Mon Sep 17 00:00:00 2001 From: TheDevYellowy Date: Mon, 1 Aug 2022 10:05:39 -0500 Subject: [PATCH 6/6] change permissions to bigint --- src/structures/interfaces/Application.js | 2 +- typings/index.d.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/structures/interfaces/Application.js b/src/structures/interfaces/Application.js index c45f24a..4d3d2c7 100644 --- a/src/structures/interfaces/Application.js +++ b/src/structures/interfaces/Application.js @@ -78,7 +78,7 @@ class Application extends Base { /** * 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 {number} [permissions] The permissions for the bot in number form (the default is 8 / Administrator) + * @param {bigint} [permissions] The permissions for the bot in number form (the default is 8 / Administrator) * @param {string} [captcha] The captcha key to add * @returns nothing :) */ diff --git a/typings/index.d.ts b/typings/index.d.ts index 5e2f8ca..a7bf9ea 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -337,7 +337,7 @@ export abstract class Application extends Base { public coverURL(options?: StaticImageURLOptions): string | null; /** @deprecated This method is deprecated as it is unsupported and will be removed in the next major version. */ public fetchAssets(): Promise; - public invite(guildID: string, permissions: number, captcha: string): null; + public invite(guildID: string, permissions: bigint, captcha: string): null; public iconURL(options?: StaticImageURLOptions): string | null; public toJSON(): unknown; public toString(): string | null;