From 403f1b58687a9401eaca056c02bb5720fea194cc Mon Sep 17 00:00:00 2001 From: SirH Date: Wed, 22 Sep 2021 01:52:57 -0400 Subject: [PATCH 01/50] feat: add support for autocomplete interactions --- src/structures/AutocompleteInteraction.js | 26 +++++++++++++++++ src/structures/BaseCommandInteraction.js | 1 + .../CommandInteractionOptionResolver.js | 12 ++++++++ src/structures/Interaction.js | 11 +++++++ .../interfaces/InteractionResponses.js | 29 +++++++++++++++++++ src/util/Constants.js | 9 +++++- typings/enums.d.ts | 2 ++ typings/index.d.ts | 13 +++++++++ 8 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 src/structures/AutocompleteInteraction.js diff --git a/src/structures/AutocompleteInteraction.js b/src/structures/AutocompleteInteraction.js new file mode 100644 index 000000000000..9052120b59b0 --- /dev/null +++ b/src/structures/AutocompleteInteraction.js @@ -0,0 +1,26 @@ +'use strict'; + +const CommandInteractionOptionResolver = require('./CommandInteractionOptionResolver'); +const Interaction = require('./Interaction'); + +/** + * Represents a autocomplete interaction. + * @extends {Interaction} + */ +class AutocompleteInteraction extends Interaction { + constructor(client, data) { + super(client, data); + + /** + * The options passed to the command. + * @type {CommandInteractionOptionResolver} + */ + this.options = new CommandInteractionOptionResolver( + this.client, + data.data.options?.map(option => this.transformOption(option, data.data.resolved)) ?? [], + this.transformResolved(data.data.resolved ?? {}), + ); + } +} + +module.exports = AutocompleteInteraction; diff --git a/src/structures/BaseCommandInteraction.js b/src/structures/BaseCommandInteraction.js index 57e2bab46e13..9726ff1f54e4 100644 --- a/src/structures/BaseCommandInteraction.js +++ b/src/structures/BaseCommandInteraction.js @@ -162,6 +162,7 @@ class BaseCommandInteraction extends Interaction { if ('value' in option) result.value = option.value; if ('options' in option) result.options = option.options.map(opt => this.transformOption(opt, resolved)); + if ('focused' in option) result.focused = option.focused; if (resolved) { const user = resolved.users?.[option.value]; diff --git a/src/structures/CommandInteractionOptionResolver.js b/src/structures/CommandInteractionOptionResolver.js index e74613f45a76..2f54d620615f 100644 --- a/src/structures/CommandInteractionOptionResolver.js +++ b/src/structures/CommandInteractionOptionResolver.js @@ -239,6 +239,18 @@ class CommandInteractionOptionResolver { const option = this._getTypedOption(name, '_MESSAGE', ['message'], required); return option?.message ?? null; } + + /** + * Gets a focused option. + * @param {name} name The name of the option. + * @param {boolean} [required=false] Whether to throw an error if the option is not found. + * @returns {?(string)} + * The value of the option, or null if not set and not required. + */ + getFocused(name, required = false) { + const option = this._getTypedOption(name, 'STRING', ['value'], required); + return option?.value ?? null; + } } module.exports = CommandInteractionOptionResolver; diff --git a/src/structures/Interaction.js b/src/structures/Interaction.js index 369c352e3ff2..66b9d1d4f0e7 100644 --- a/src/structures/Interaction.js +++ b/src/structures/Interaction.js @@ -129,6 +129,17 @@ class Interaction extends Base { return InteractionTypes[this.type] === InteractionTypes.APPLICATION_COMMAND && typeof this.targetId !== 'undefined'; } + /** + * Indicates whether this interaction is a {@link AutocompleteInteraction} + * @returns {boolean} + */ + isAutocomplete() { + return ( + InteractionTypes[this.type] === InteractionTypes.APPLICATION_COMMAND_AUTOCOMPLETE && + typeof this.targetId === 'undefined' + ); + } + /** * Indicates whether this interaction is a {@link MessageComponentInteraction}. * @returns {boolean} diff --git a/src/structures/interfaces/InteractionResponses.js b/src/structures/interfaces/InteractionResponses.js index 8a36d8204605..3a6fa0fe2727 100644 --- a/src/structures/interfaces/InteractionResponses.js +++ b/src/structures/interfaces/InteractionResponses.js @@ -218,6 +218,35 @@ class InteractionResponses { return options.fetchReply ? this.fetchReply() : undefined; } + /** + * Sends results for the autocomplete of this interaction. + * @param {InteractionResultOptions} options The options for the autocomplete + * @returns {Promise} + * @example + * // respond to autocomplete interaction + * interaction.autocomplete({ + * options: [ + * { + * name: 'Option 1', + * value: 'option1', + * }, + * ], + * }) + * .then(console.log) + * .catch(console.error); + */ + async result(options) { + if (this.replied) throw new Error('INTERACTION_ALREADY_REPLIED'); + + await this.client.api.interactions(this.id, this.token).callback.post({ + data: { + type: InteractionResponseTypes.APPLICATION_COMMAND_AUTOCOMPLETE_RESULT, + data: options, + }, + }); + this.replied = true; + } + static applyToClass(structure, ignore = []) { const props = [ 'deferReply', diff --git a/src/util/Constants.js b/src/util/Constants.js index c59f4b5b2a78..278d13568998 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -954,7 +954,13 @@ exports.ApplicationCommandPermissionTypes = createEnum([null, 'ROLE', 'USER']); * @typedef {string} InteractionType * @see {@link https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-type} */ -exports.InteractionTypes = createEnum([null, 'PING', 'APPLICATION_COMMAND', 'MESSAGE_COMPONENT']); +exports.InteractionTypes = createEnum([ + null, + 'PING', + 'APPLICATION_COMMAND', + 'MESSAGE_COMPONENT', + 'APPLICATION_COMMAND_AUTOCOMPLETE', +]); /** * The type of an interaction response: @@ -975,6 +981,7 @@ exports.InteractionResponseTypes = createEnum([ 'DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE', 'DEFERRED_MESSAGE_UPDATE', 'UPDATE_MESSAGE', + 'APPLICATION_COMMAND_AUTOCOMPLETE_RESULT', ]); /* eslint-enable max-len */ diff --git a/typings/enums.d.ts b/typings/enums.d.ts index 1a27f547026b..515409c330d8 100644 --- a/typings/enums.d.ts +++ b/typings/enums.d.ts @@ -66,12 +66,14 @@ export const enum InteractionResponseTypes { DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE = 5, DEFERRED_MESSAGE_UPDATE = 6, UPDATE_MESSAGE = 7, + APPLICATION_COMMAND_AUTOCOMPLETE_RESULT = 8, } export const enum InteractionTypes { PING = 1, APPLICATION_COMMAND = 2, MESSAGE_COMPONENT = 3, + APPLICATION_COMMAND_AUTOCOMPLETE = 4, } export const enum InviteTargetType { diff --git a/typings/index.d.ts b/typings/index.d.ts index e54cb3bc89ca..44202227bf4c 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -557,6 +557,11 @@ export class CommandInteraction extends BaseCommandInteraction { public options: CommandInteractionOptionResolver; } +export class AutocompleteInteraction extends Interaction { + public options: CommandInteractionOptionResolver; + public result: (name: string, required: boolean) => Promise; +} + export class CommandInteractionOptionResolver { public constructor(client: Client, options: CommandInteractionOption[], resolved: CommandInteractionResolvedData); public readonly client: Client; @@ -611,6 +616,7 @@ export class CommandInteractionOptionResolver { ): NonNullable | null; public getMessage(name: string, required: true): NonNullable; public getMessage(name: string, required?: boolean): NonNullable | null; + public getFocused(name: string, require?: boolean): string | null; } export class ContextMenuInteraction extends BaseCommandInteraction { @@ -1025,6 +1031,7 @@ export class Interaction extends Base { public inGuild(): this is this & { guildId: Snowflake; member: GuildMember | APIInteractionGuildMember }; public isButton(): this is ButtonInteraction; public isCommand(): this is CommandInteraction; + public isAutocomplete(): this is AutocompleteInteraction; public isContextMenu(): this is ContextMenuInteraction; public isMessageComponent(): this is MessageComponentInteraction; public isSelectMenu(): this is SelectMenuInteraction; @@ -3432,6 +3439,8 @@ export interface CommandInteractionOption { name: string; type: ApplicationCommandOptionType; value?: string | number | boolean; + autocomplete?: boolean; + focused?: boolean; options?: CommandInteractionOption[]; user?: User; member?: GuildMember | APIInteractionDataResolvedGuildMember; @@ -4073,6 +4082,10 @@ export interface InteractionUpdateOptions extends MessageEditOptions { fetchReply?: boolean; } +export interface InteractionResultOptions { + options: CommandInteractionOption[]; +} + export type IntentsString = | 'GUILDS' | 'GUILD_MEMBERS' From 9a8d142d1a7ef60a9534d4966455a39eaa241116 Mon Sep 17 00:00:00 2001 From: SirH Date: Wed, 22 Sep 2021 03:58:32 -0400 Subject: [PATCH 02/50] fix: redid some bits of the implementation --- src/client/actions/InteractionCreate.js | 4 +++ src/structures/AutocompleteInteraction.js | 34 +++++++++++++++++-- .../CommandInteractionOptionResolver.js | 14 ++++---- src/structures/Interaction.js | 5 +-- .../interfaces/InteractionResponses.js | 29 ---------------- typings/index.d.ts | 10 +++--- 6 files changed, 49 insertions(+), 47 deletions(-) diff --git a/src/client/actions/InteractionCreate.js b/src/client/actions/InteractionCreate.js index eeb68c0bcc9b..ddbc097a695f 100644 --- a/src/client/actions/InteractionCreate.js +++ b/src/client/actions/InteractionCreate.js @@ -1,6 +1,7 @@ 'use strict'; const Action = require('./Action'); +const AutocompleteInteraction = require('../../structures/AutocompleteInteraction'); const ButtonInteraction = require('../../structures/ButtonInteraction'); const CommandInteraction = require('../../structures/CommandInteraction'); const ContextMenuInteraction = require('../../structures/ContextMenuInteraction'); @@ -51,6 +52,9 @@ class InteractionCreateAction extends Action { return; } break; + case InteractionTypes.APPLICATION_COMMAND_AUTOCOMPLETE: + InteractionType = AutocompleteInteraction; + break; default: client.emit(Events.DEBUG, `[INTERACTION] Received interaction with unknown type: ${data.type}`); return; diff --git a/src/structures/AutocompleteInteraction.js b/src/structures/AutocompleteInteraction.js index 9052120b59b0..4f38bc790272 100644 --- a/src/structures/AutocompleteInteraction.js +++ b/src/structures/AutocompleteInteraction.js @@ -1,13 +1,14 @@ 'use strict'; +const BaseCommandInteraction = require('./BaseCommandInteraction'); const CommandInteractionOptionResolver = require('./CommandInteractionOptionResolver'); -const Interaction = require('./Interaction'); +const { InteractionResponseTypes } = require('../util/Constants'); /** * Represents a autocomplete interaction. * @extends {Interaction} */ -class AutocompleteInteraction extends Interaction { +class AutocompleteInteraction extends BaseCommandInteraction { constructor(client, data) { super(client, data); @@ -21,6 +22,35 @@ class AutocompleteInteraction extends Interaction { this.transformResolved(data.data.resolved ?? {}), ); } + + /** + * Sends results for the autocomplete of this interaction. + * @param {InteractionResultOptions} options The options for the autocomplete + * @returns {Promise} + * @example + * // respond to autocomplete interaction + * interaction.result({ + * options: [ + * { + * name: 'Option 1', + * value: 'option1', + * }, + * ], + * }) + * .then(console.log) + * .catch(console.error); + */ + async result(options) { + if (this.replied) throw new Error('INTERACTION_ALREADY_REPLIED'); + + await this.client.api.interactions(this.id, this.token).callback.post({ + data: { + type: InteractionResponseTypes.APPLICATION_COMMAND_AUTOCOMPLETE_RESULT, + data: options, + }, + }); + this.replied = true; + } } module.exports = AutocompleteInteraction; diff --git a/src/structures/CommandInteractionOptionResolver.js b/src/structures/CommandInteractionOptionResolver.js index 2f54d620615f..50f3298d136d 100644 --- a/src/structures/CommandInteractionOptionResolver.js +++ b/src/structures/CommandInteractionOptionResolver.js @@ -241,15 +241,17 @@ class CommandInteractionOptionResolver { } /** - * Gets a focused option. - * @param {name} name The name of the option. + * Gets the focused option. * @param {boolean} [required=false] Whether to throw an error if the option is not found. - * @returns {?(string)} + * @returns {?(string|number)} * The value of the option, or null if not set and not required. */ - getFocused(name, required = false) { - const option = this._getTypedOption(name, 'STRING', ['value'], required); - return option?.value ?? null; + getFocused(required = false) { + const focusedOption = this._hoistedOptions.find(option => option.focused); + if (required && !focusedOption) { + throw new TypeError('AUTOCOMPLETE_INTERACTION_OPTION_NO_FOCUSED_OPTION'); + } + return focusedOption?.value ?? null; } } diff --git a/src/structures/Interaction.js b/src/structures/Interaction.js index 66b9d1d4f0e7..c21a037eeb84 100644 --- a/src/structures/Interaction.js +++ b/src/structures/Interaction.js @@ -134,10 +134,7 @@ class Interaction extends Base { * @returns {boolean} */ isAutocomplete() { - return ( - InteractionTypes[this.type] === InteractionTypes.APPLICATION_COMMAND_AUTOCOMPLETE && - typeof this.targetId === 'undefined' - ); + return InteractionTypes[this.type] === InteractionTypes.APPLICATION_COMMAND_AUTOCOMPLETE; } /** diff --git a/src/structures/interfaces/InteractionResponses.js b/src/structures/interfaces/InteractionResponses.js index 3a6fa0fe2727..8a36d8204605 100644 --- a/src/structures/interfaces/InteractionResponses.js +++ b/src/structures/interfaces/InteractionResponses.js @@ -218,35 +218,6 @@ class InteractionResponses { return options.fetchReply ? this.fetchReply() : undefined; } - /** - * Sends results for the autocomplete of this interaction. - * @param {InteractionResultOptions} options The options for the autocomplete - * @returns {Promise} - * @example - * // respond to autocomplete interaction - * interaction.autocomplete({ - * options: [ - * { - * name: 'Option 1', - * value: 'option1', - * }, - * ], - * }) - * .then(console.log) - * .catch(console.error); - */ - async result(options) { - if (this.replied) throw new Error('INTERACTION_ALREADY_REPLIED'); - - await this.client.api.interactions(this.id, this.token).callback.post({ - data: { - type: InteractionResponseTypes.APPLICATION_COMMAND_AUTOCOMPLETE_RESULT, - data: options, - }, - }); - this.replied = true; - } - static applyToClass(structure, ignore = []) { const props = [ 'deferReply', diff --git a/typings/index.d.ts b/typings/index.d.ts index 44202227bf4c..e02fb85382fe 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -559,7 +559,7 @@ export class CommandInteraction extends BaseCommandInteraction { export class AutocompleteInteraction extends Interaction { public options: CommandInteractionOptionResolver; - public result: (name: string, required: boolean) => Promise; + public result: (options: InteractionResultOptions) => Promise; } export class CommandInteractionOptionResolver { @@ -616,7 +616,7 @@ export class CommandInteractionOptionResolver { ): NonNullable | null; public getMessage(name: string, required: true): NonNullable; public getMessage(name: string, required?: boolean): NonNullable | null; - public getFocused(name: string, require?: boolean): string | null; + public getFocused(require?: boolean): string | number | null; } export class ContextMenuInteraction extends BaseCommandInteraction { @@ -3439,8 +3439,8 @@ export interface CommandInteractionOption { name: string; type: ApplicationCommandOptionType; value?: string | number | boolean; - autocomplete?: boolean; focused?: boolean; + autocomplete?: boolean; options?: CommandInteractionOption[]; user?: User; member?: GuildMember | APIInteractionDataResolvedGuildMember; @@ -4082,9 +4082,7 @@ export interface InteractionUpdateOptions extends MessageEditOptions { fetchReply?: boolean; } -export interface InteractionResultOptions { - options: CommandInteractionOption[]; -} +export type InteractionResultOptions = CommandInteractionOption[]; export type IntentsString = | 'GUILDS' From dca6b71757e45466c9701d07f0e98d3496a02cb5 Mon Sep 17 00:00:00 2001 From: SirH Date: Wed, 22 Sep 2021 04:17:51 -0400 Subject: [PATCH 03/50] types: autocomplete extends --- src/structures/AutocompleteInteraction.js | 2 +- typings/index.d.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/structures/AutocompleteInteraction.js b/src/structures/AutocompleteInteraction.js index 4f38bc790272..eea57189ba15 100644 --- a/src/structures/AutocompleteInteraction.js +++ b/src/structures/AutocompleteInteraction.js @@ -6,7 +6,7 @@ const { InteractionResponseTypes } = require('../util/Constants'); /** * Represents a autocomplete interaction. - * @extends {Interaction} + * @extends {BaseCommandInteraction} */ class AutocompleteInteraction extends BaseCommandInteraction { constructor(client, data) { diff --git a/typings/index.d.ts b/typings/index.d.ts index e02fb85382fe..cbfbc66d586d 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -557,7 +557,7 @@ export class CommandInteraction extends BaseCommandInteraction { public options: CommandInteractionOptionResolver; } -export class AutocompleteInteraction extends Interaction { +export class AutocompleteInteraction extends BaseCommandInteraction { public options: CommandInteractionOptionResolver; public result: (options: InteractionResultOptions) => Promise; } From 1e44487de1571583e438723dc7c2287e0dbd0666 Mon Sep 17 00:00:00 2001 From: SirH Date: Wed, 22 Sep 2021 10:14:05 -0400 Subject: [PATCH 04/50] fix: indentation and grammar --- src/structures/AutocompleteInteraction.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/structures/AutocompleteInteraction.js b/src/structures/AutocompleteInteraction.js index eea57189ba15..d6fae77516f2 100644 --- a/src/structures/AutocompleteInteraction.js +++ b/src/structures/AutocompleteInteraction.js @@ -5,7 +5,7 @@ const CommandInteractionOptionResolver = require('./CommandInteractionOptionReso const { InteractionResponseTypes } = require('../util/Constants'); /** - * Represents a autocomplete interaction. + * Represents an autocomplete interaction. * @extends {BaseCommandInteraction} */ class AutocompleteInteraction extends BaseCommandInteraction { @@ -38,7 +38,7 @@ class AutocompleteInteraction extends BaseCommandInteraction { * ], * }) * .then(console.log) - * .catch(console.error); + * .catch(console.error); */ async result(options) { if (this.replied) throw new Error('INTERACTION_ALREADY_REPLIED'); From d775631b65799c1e33ab072f9245850d7bfa363c Mon Sep 17 00:00:00 2001 From: SirH Date: Wed, 22 Sep 2021 10:27:57 -0400 Subject: [PATCH 05/50] fix: example for result method --- src/structures/AutocompleteInteraction.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/structures/AutocompleteInteraction.js b/src/structures/AutocompleteInteraction.js index d6fae77516f2..8947997a2242 100644 --- a/src/structures/AutocompleteInteraction.js +++ b/src/structures/AutocompleteInteraction.js @@ -29,14 +29,12 @@ class AutocompleteInteraction extends BaseCommandInteraction { * @returns {Promise} * @example * // respond to autocomplete interaction - * interaction.result({ - * options: [ - * { + * interaction.result([ + * { * name: 'Option 1', * value: 'option1', - * }, - * ], - * }) + * }, + * ]) * .then(console.log) * .catch(console.error); */ From 6edb15576e92749d1d2016993d0bb1b0af0d0627 Mon Sep 17 00:00:00 2001 From: SirH Date: Wed, 22 Sep 2021 10:31:26 -0400 Subject: [PATCH 06/50] types: readjust result to consistent typing --- 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 cbfbc66d586d..ea376769dfcc 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -559,7 +559,7 @@ export class CommandInteraction extends BaseCommandInteraction { export class AutocompleteInteraction extends BaseCommandInteraction { public options: CommandInteractionOptionResolver; - public result: (options: InteractionResultOptions) => Promise; + public result(options: InteractionResultOptions): Promise; } export class CommandInteractionOptionResolver { From fc9bd0119a8626f1bb38748b36678f27d8bee294 Mon Sep 17 00:00:00 2001 From: SirH Date: Wed, 22 Sep 2021 11:17:11 -0400 Subject: [PATCH 07/50] types: update options for result method --- 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 ea376769dfcc..23fb43ca37c6 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -4082,7 +4082,7 @@ export interface InteractionUpdateOptions extends MessageEditOptions { fetchReply?: boolean; } -export type InteractionResultOptions = CommandInteractionOption[]; +export type InteractionResultOptions = ApplicationCommandOptionChoice[]; export type IntentsString = | 'GUILDS' From 32dadaeb3a58f8e9dde009e5c88ba7c3aa592ad4 Mon Sep 17 00:00:00 2001 From: SirH Date: Wed, 22 Sep 2021 11:44:08 -0400 Subject: [PATCH 08/50] types: add missing types --- typings/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/typings/index.d.ts b/typings/index.d.ts index 23fb43ca37c6..6676c955e26e 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -3041,6 +3041,7 @@ export interface BaseApplicationCommandOptionsData { name: string; description: string; required?: boolean; + autocomplete?: boolean; } export interface UserApplicationCommandData extends BaseApplicationCommandData { From 7aad00879a7e4d04556aa4bacf91868c32606d29 Mon Sep 17 00:00:00 2001 From: SirH Date: Wed, 22 Sep 2021 12:01:35 -0400 Subject: [PATCH 09/50] fix: grammar and formatting --- src/structures/AutocompleteInteraction.js | 2 +- src/structures/CommandInteractionOptionResolver.js | 3 +-- src/structures/Interaction.js | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/structures/AutocompleteInteraction.js b/src/structures/AutocompleteInteraction.js index 8947997a2242..ad02639c8a01 100644 --- a/src/structures/AutocompleteInteraction.js +++ b/src/structures/AutocompleteInteraction.js @@ -13,7 +13,7 @@ class AutocompleteInteraction extends BaseCommandInteraction { super(client, data); /** - * The options passed to the command. + * The options passed to the command * @type {CommandInteractionOptionResolver} */ this.options = new CommandInteractionOptionResolver( diff --git a/src/structures/CommandInteractionOptionResolver.js b/src/structures/CommandInteractionOptionResolver.js index 50f3298d136d..67c9ee350fa1 100644 --- a/src/structures/CommandInteractionOptionResolver.js +++ b/src/structures/CommandInteractionOptionResolver.js @@ -243,8 +243,7 @@ class CommandInteractionOptionResolver { /** * Gets the focused option. * @param {boolean} [required=false] Whether to throw an error if the option is not found. - * @returns {?(string|number)} - * The value of the option, or null if not set and not required. + * @returns {?(string|number)} The value of the option, or null if not set and not required. */ getFocused(required = false) { const focusedOption = this._hoistedOptions.find(option => option.focused); diff --git a/src/structures/Interaction.js b/src/structures/Interaction.js index c21a037eeb84..ad74e9051dc2 100644 --- a/src/structures/Interaction.js +++ b/src/structures/Interaction.js @@ -130,7 +130,7 @@ class Interaction extends Base { } /** - * Indicates whether this interaction is a {@link AutocompleteInteraction} + * Indicates whether this interaction is an {@link AutocompleteInteraction} * @returns {boolean} */ isAutocomplete() { From 4ad3d22c5acf4cd4af898a42c1cc05e3aa57f84a Mon Sep 17 00:00:00 2001 From: SirH Date: Wed, 22 Sep 2021 12:20:16 -0400 Subject: [PATCH 10/50] fix: transformCommand method allows autocomplete --- src/structures/ApplicationCommand.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/structures/ApplicationCommand.js b/src/structures/ApplicationCommand.js index 2a90b38b764c..fcb99eb5c9fe 100644 --- a/src/structures/ApplicationCommand.js +++ b/src/structures/ApplicationCommand.js @@ -301,6 +301,7 @@ class ApplicationCommand extends Base { description: option.description, required: option.required ?? (stringType === 'SUB_COMMAND' || stringType === 'SUB_COMMAND_GROUP' ? undefined : false), + autocomplete: option.autocomplete, choices: option.choices, options: option.options?.map(o => this.transformOption(o, received)), }; From 1e491c1d07cf8d7f442bc18a9999f225ba275183 Mon Sep 17 00:00:00 2001 From: SirH Date: Wed, 22 Sep 2021 12:31:11 -0400 Subject: [PATCH 11/50] fix: result method's callback --- src/structures/AutocompleteInteraction.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/structures/AutocompleteInteraction.js b/src/structures/AutocompleteInteraction.js index ad02639c8a01..fb109cb82283 100644 --- a/src/structures/AutocompleteInteraction.js +++ b/src/structures/AutocompleteInteraction.js @@ -44,7 +44,9 @@ class AutocompleteInteraction extends BaseCommandInteraction { await this.client.api.interactions(this.id, this.token).callback.post({ data: { type: InteractionResponseTypes.APPLICATION_COMMAND_AUTOCOMPLETE_RESULT, - data: options, + data: { + choices: options, + }, }, }); this.replied = true; From f93253c7fb7db29982c55751c7265d4f9fe2f0e7 Mon Sep 17 00:00:00 2001 From: SirH Date: Wed, 22 Sep 2021 13:36:51 -0400 Subject: [PATCH 12/50] fix: getFocused method return --- src/structures/CommandInteractionOptionResolver.js | 6 +++--- typings/index.d.ts | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/structures/CommandInteractionOptionResolver.js b/src/structures/CommandInteractionOptionResolver.js index 67c9ee350fa1..86b04cc79db9 100644 --- a/src/structures/CommandInteractionOptionResolver.js +++ b/src/structures/CommandInteractionOptionResolver.js @@ -242,15 +242,15 @@ class CommandInteractionOptionResolver { /** * Gets the focused option. - * @param {boolean} [required=false] Whether to throw an error if the option is not found. - * @returns {?(string|number)} The value of the option, or null if not set and not required. + * @param {boolean} [required=false] Whether to throw an error if the option is not found + * @returns {?(string|number)} The value of the option, or null if not set and not required */ getFocused(required = false) { const focusedOption = this._hoistedOptions.find(option => option.focused); if (required && !focusedOption) { throw new TypeError('AUTOCOMPLETE_INTERACTION_OPTION_NO_FOCUSED_OPTION'); } - return focusedOption?.value ?? null; + return focusedOption ?? null; } } diff --git a/typings/index.d.ts b/typings/index.d.ts index 6676c955e26e..0fbe17bf41a4 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -616,7 +616,8 @@ export class CommandInteractionOptionResolver { ): NonNullable | null; public getMessage(name: string, required: true): NonNullable; public getMessage(name: string, required?: boolean): NonNullable | null; - public getFocused(require?: boolean): string | number | null; + public getFocused(require: true): ApplicationCommandOptionChoice; + public getFocused(require?: boolean): ApplicationCommandOptionChoice | null; } export class ContextMenuInteraction extends BaseCommandInteraction { From 56cc153632ff0de966c4faf3c62c53b16ec9debc Mon Sep 17 00:00:00 2001 From: SirH Date: Wed, 22 Sep 2021 14:31:32 -0400 Subject: [PATCH 13/50] types: replace unecessary type --- src/structures/AutocompleteInteraction.js | 2 +- typings/index.d.ts | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/structures/AutocompleteInteraction.js b/src/structures/AutocompleteInteraction.js index fb109cb82283..ffbf0b40c88a 100644 --- a/src/structures/AutocompleteInteraction.js +++ b/src/structures/AutocompleteInteraction.js @@ -25,7 +25,7 @@ class AutocompleteInteraction extends BaseCommandInteraction { /** * Sends results for the autocomplete of this interaction. - * @param {InteractionResultOptions} options The options for the autocomplete + * @param {ApplicationCommandOptionChoice[]} options The options for the autocomplete * @returns {Promise} * @example * // respond to autocomplete interaction diff --git a/typings/index.d.ts b/typings/index.d.ts index 0fbe17bf41a4..1077724f9b75 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -559,7 +559,7 @@ export class CommandInteraction extends BaseCommandInteraction { export class AutocompleteInteraction extends BaseCommandInteraction { public options: CommandInteractionOptionResolver; - public result(options: InteractionResultOptions): Promise; + public result(options: ApplicationCommandOptionChoice[]): Promise; } export class CommandInteractionOptionResolver { @@ -4084,8 +4084,6 @@ export interface InteractionUpdateOptions extends MessageEditOptions { fetchReply?: boolean; } -export type InteractionResultOptions = ApplicationCommandOptionChoice[]; - export type IntentsString = | 'GUILDS' | 'GUILD_MEMBERS' From afa28593d534404c4dd016b1ba0754bcf54e62a8 Mon Sep 17 00:00:00 2001 From: SirH Date: Thu, 23 Sep 2021 07:29:35 -0400 Subject: [PATCH 14/50] fix: definitions and methods for autocomplete interaction --- src/structures/ApplicationCommand.js | 2 + src/structures/AutocompleteInteraction.js | 45 ++++++++++++++++--- src/structures/BaseCommandInteraction.js | 2 +- .../CommandInteractionOptionResolver.js | 13 +++--- typings/index.d.ts | 9 ++-- 5 files changed, 53 insertions(+), 18 deletions(-) diff --git a/src/structures/ApplicationCommand.js b/src/structures/ApplicationCommand.js index fcb99eb5c9fe..ba1bcf7e9372 100644 --- a/src/structures/ApplicationCommand.js +++ b/src/structures/ApplicationCommand.js @@ -128,6 +128,7 @@ class ApplicationCommand extends Base { * @property {ApplicationCommandOptionType|number} type The type of the option * @property {string} name The name of the option * @property {string} description The description of the option + * @property {boolean} [autocomplete] Whether the option is an autocomplete option * @property {boolean} [required] Whether the option is required * @property {ApplicationCommandOptionChoice[]} [choices] The choices of the option for the user to pick from * @property {ApplicationCommandOptionData[]} [options] Additional options if this option is a subcommand (group) @@ -275,6 +276,7 @@ class ApplicationCommand extends Base { * @property {string} name The name of the option * @property {string} description The description of the option * @property {boolean} [required] Whether the option is required + * @property {boolean} [autocomplete] Whether the option is an autocomplete option * @property {ApplicationCommandOptionChoice[]} [choices] The choices of the option for the user to pick from * @property {ApplicationCommandOption[]} [options] Additional options if this option is a subcommand (group) */ diff --git a/src/structures/AutocompleteInteraction.js b/src/structures/AutocompleteInteraction.js index ffbf0b40c88a..8c5b77cca9df 100644 --- a/src/structures/AutocompleteInteraction.js +++ b/src/structures/AutocompleteInteraction.js @@ -1,14 +1,14 @@ 'use strict'; -const BaseCommandInteraction = require('./BaseCommandInteraction'); const CommandInteractionOptionResolver = require('./CommandInteractionOptionResolver'); -const { InteractionResponseTypes } = require('../util/Constants'); +const Interaction = require('./Interaction'); +const { InteractionResponseTypes, ApplicationCommandOptionTypes } = require('../util/Constants'); /** * Represents an autocomplete interaction. - * @extends {BaseCommandInteraction} + * @extends {Interaction} */ -class AutocompleteInteraction extends BaseCommandInteraction { +class AutocompleteInteraction extends Interaction { constructor(client, data) { super(client, data); @@ -19,17 +19,50 @@ class AutocompleteInteraction extends BaseCommandInteraction { this.options = new CommandInteractionOptionResolver( this.client, data.data.options?.map(option => this.transformOption(option, data.data.resolved)) ?? [], - this.transformResolved(data.data.resolved ?? {}), ); } + /** + * Transforms an option received from the API. + * @param {APIApplicationCommandOption} option The received option + * @param {APIInteractionDataResolved} resolved The resolved interaction data + * @returns {CommandInteractionOption} + * @private + */ + transformOption(option, resolved) { + const result = { + name: option.name, + type: ApplicationCommandOptionTypes[option.type], + }; + + if ('value' in option) result.value = option.value; + if ('options' in option) result.options = option.options.map(opt => this.transformOption(opt, resolved)); + if ('focused' in option) result.focused = option.focused; + + if (resolved) { + const user = resolved.users?.[option.value]; + if (user) result.user = this.client.users._add(user); + + const member = resolved.members?.[option.value]; + if (member) result.member = this.guild?.members._add({ user, ...member }) ?? member; + + const channel = resolved.channels?.[option.value]; + if (channel) result.channel = this.client.channels._add(channel, this.guild) ?? channel; + + const role = resolved.roles?.[option.value]; + if (role) result.role = this.guild?.roles._add(role) ?? role; + } + + return result; + } + /** * Sends results for the autocomplete of this interaction. * @param {ApplicationCommandOptionChoice[]} options The options for the autocomplete * @returns {Promise} * @example * // respond to autocomplete interaction - * interaction.result([ + * interaction.sendResult([ * { * name: 'Option 1', * value: 'option1', diff --git a/src/structures/BaseCommandInteraction.js b/src/structures/BaseCommandInteraction.js index 9726ff1f54e4..5cc2b0cb4097 100644 --- a/src/structures/BaseCommandInteraction.js +++ b/src/structures/BaseCommandInteraction.js @@ -138,6 +138,7 @@ class BaseCommandInteraction extends Interaction { * @typedef {Object} CommandInteractionOption * @property {string} name The name of the option * @property {ApplicationCommandOptionType} type The type of the option + * @property {boolean} [autocomplete] Whether the option is an autocomplete option * @property {string|number|boolean} [value] The value of the option * @property {CommandInteractionOption[]} [options] Additional options if this option is a * subcommand (group) @@ -162,7 +163,6 @@ class BaseCommandInteraction extends Interaction { if ('value' in option) result.value = option.value; if ('options' in option) result.options = option.options.map(opt => this.transformOption(opt, resolved)); - if ('focused' in option) result.focused = option.focused; if (resolved) { const user = resolved.users?.[option.value]; diff --git a/src/structures/CommandInteractionOptionResolver.js b/src/structures/CommandInteractionOptionResolver.js index 86b04cc79db9..2f7634e5dda6 100644 --- a/src/structures/CommandInteractionOptionResolver.js +++ b/src/structures/CommandInteractionOptionResolver.js @@ -242,15 +242,14 @@ class CommandInteractionOptionResolver { /** * Gets the focused option. - * @param {boolean} [required=false] Whether to throw an error if the option is not found - * @returns {?(string|number)} The value of the option, or null if not set and not required + * @param {boolean} [getFull=false] Whether to throw an error if the option is not found + * @returns {string|number|ApplicationCommandOptionChoice} + * The value of the option, or the whole option if getFull is true */ - getFocused(required = false) { + getFocused(getFull = false) { const focusedOption = this._hoistedOptions.find(option => option.focused); - if (required && !focusedOption) { - throw new TypeError('AUTOCOMPLETE_INTERACTION_OPTION_NO_FOCUSED_OPTION'); - } - return focusedOption ?? null; + if (!focusedOption) throw new TypeError('AUTOCOMPLETE_INTERACTION_OPTION_NO_FOCUSED_OPTION'); + return getFull ? focusedOption : focusedOption.value; } } diff --git a/typings/index.d.ts b/typings/index.d.ts index 1077724f9b75..26c92968e926 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -557,9 +557,10 @@ export class CommandInteraction extends BaseCommandInteraction { public options: CommandInteractionOptionResolver; } -export class AutocompleteInteraction extends BaseCommandInteraction { +export class AutocompleteInteraction extends Interaction { public options: CommandInteractionOptionResolver; - public result(options: ApplicationCommandOptionChoice[]): Promise; + private transformOption(option: APIApplicationCommandOption, resolved: null): CommandInteractionOption; + public sendResult(options: ApplicationCommandOptionChoice[]): Promise; } export class CommandInteractionOptionResolver { @@ -616,8 +617,8 @@ export class CommandInteractionOptionResolver { ): NonNullable | null; public getMessage(name: string, required: true): NonNullable; public getMessage(name: string, required?: boolean): NonNullable | null; - public getFocused(require: true): ApplicationCommandOptionChoice; - public getFocused(require?: boolean): ApplicationCommandOptionChoice | null; + public getFocused(getFull: true): ApplicationCommandOptionChoice; + public getFocused(getFull?: boolean): string | number; } export class ContextMenuInteraction extends BaseCommandInteraction { From 162aad078d5db3650396a49f0bfc7f60f6d87bff Mon Sep 17 00:00:00 2001 From: SirH Date: Thu, 23 Sep 2021 08:19:50 -0400 Subject: [PATCH 15/50] fix: inconsistencies and methods --- src/errors/Messages.js | 1 + src/structures/AutocompleteInteraction.js | 23 ++++--------------- .../CommandInteractionOptionResolver.js | 2 +- typings/index.d.ts | 4 ++-- 4 files changed, 8 insertions(+), 22 deletions(-) diff --git a/src/errors/Messages.js b/src/errors/Messages.js index f99dd2d97724..b9df038dd848 100644 --- a/src/errors/Messages.js +++ b/src/errors/Messages.js @@ -142,6 +142,7 @@ const Messages = { `Required option "${name}" is of type: ${type}; expected a non-empty value.`, COMMAND_INTERACTION_OPTION_NO_SUB_COMMAND: 'No subcommand specified for interaction.', COMMAND_INTERACTION_OPTION_NO_SUB_COMMAND_GROUP: 'No subcommand group specified for interaction.', + AUTOCOMPLETE_INTERACTION_OPTION_NO_FOCUSED_OPTION: 'No focused option for autocomplete interaction.', INVITE_MISSING_SCOPES: 'At least one valid scope must be provided for the invite', diff --git a/src/structures/AutocompleteInteraction.js b/src/structures/AutocompleteInteraction.js index 8c5b77cca9df..5b0e86a7513a 100644 --- a/src/structures/AutocompleteInteraction.js +++ b/src/structures/AutocompleteInteraction.js @@ -25,34 +25,19 @@ class AutocompleteInteraction extends Interaction { /** * Transforms an option received from the API. * @param {APIApplicationCommandOption} option The received option - * @param {APIInteractionDataResolved} resolved The resolved interaction data * @returns {CommandInteractionOption} * @private */ - transformOption(option, resolved) { + transformOption(option) { const result = { name: option.name, type: ApplicationCommandOptionTypes[option.type], }; if ('value' in option) result.value = option.value; - if ('options' in option) result.options = option.options.map(opt => this.transformOption(opt, resolved)); + if ('options' in option) result.options = option.options.map(opt => this.transformOption(opt)); if ('focused' in option) result.focused = option.focused; - if (resolved) { - const user = resolved.users?.[option.value]; - if (user) result.user = this.client.users._add(user); - - const member = resolved.members?.[option.value]; - if (member) result.member = this.guild?.members._add({ user, ...member }) ?? member; - - const channel = resolved.channels?.[option.value]; - if (channel) result.channel = this.client.channels._add(channel, this.guild) ?? channel; - - const role = resolved.roles?.[option.value]; - if (role) result.role = this.guild?.roles._add(role) ?? role; - } - return result; } @@ -62,7 +47,7 @@ class AutocompleteInteraction extends Interaction { * @returns {Promise} * @example * // respond to autocomplete interaction - * interaction.sendResult([ + * interaction.respond([ * { * name: 'Option 1', * value: 'option1', @@ -71,7 +56,7 @@ class AutocompleteInteraction extends Interaction { * .then(console.log) * .catch(console.error); */ - async result(options) { + async respond(options) { if (this.replied) throw new Error('INTERACTION_ALREADY_REPLIED'); await this.client.api.interactions(this.id, this.token).callback.post({ diff --git a/src/structures/CommandInteractionOptionResolver.js b/src/structures/CommandInteractionOptionResolver.js index 2f7634e5dda6..c83fd8e2f00e 100644 --- a/src/structures/CommandInteractionOptionResolver.js +++ b/src/structures/CommandInteractionOptionResolver.js @@ -242,7 +242,7 @@ class CommandInteractionOptionResolver { /** * Gets the focused option. - * @param {boolean} [getFull=false] Whether to throw an error if the option is not found + * @param {boolean} [getFull=false] Whether to get the full option object * @returns {string|number|ApplicationCommandOptionChoice} * The value of the option, or the whole option if getFull is true */ diff --git a/typings/index.d.ts b/typings/index.d.ts index 26c92968e926..f91c0f4ab200 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -559,8 +559,8 @@ export class CommandInteraction extends BaseCommandInteraction { export class AutocompleteInteraction extends Interaction { public options: CommandInteractionOptionResolver; - private transformOption(option: APIApplicationCommandOption, resolved: null): CommandInteractionOption; - public sendResult(options: ApplicationCommandOptionChoice[]): Promise; + private transformOption(option: APIApplicationCommandOption): CommandInteractionOption; + public respond(options: ApplicationCommandOptionChoice[]): Promise; } export class CommandInteractionOptionResolver { From d59e41106f98e686d1c1af15434822beb8ef3055 Mon Sep 17 00:00:00 2001 From: SirH Date: Thu, 23 Sep 2021 09:49:10 -0400 Subject: [PATCH 16/50] fix: missing properties --- src/structures/AutocompleteInteraction.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/structures/AutocompleteInteraction.js b/src/structures/AutocompleteInteraction.js index 5b0e86a7513a..226d06e77448 100644 --- a/src/structures/AutocompleteInteraction.js +++ b/src/structures/AutocompleteInteraction.js @@ -12,6 +12,24 @@ class AutocompleteInteraction extends Interaction { constructor(client, data) { super(client, data); + /** + * The invoked application command's id + * @type {Snowflake} + */ + this.commandId = data.data.id; + + /** + * The invoked application command's name + * @type {string} + */ + this.commandName = data.data.name; + + /** + * Whether this interaction has already received a response + * @type {boolean} + */ + this.responded = false; + /** * The options passed to the command * @type {CommandInteractionOptionResolver} @@ -57,7 +75,7 @@ class AutocompleteInteraction extends Interaction { * .catch(console.error); */ async respond(options) { - if (this.replied) throw new Error('INTERACTION_ALREADY_REPLIED'); + if (this.responded) throw new Error('INTERACTION_ALREADY_REPLIED'); await this.client.api.interactions(this.id, this.token).callback.post({ data: { @@ -67,7 +85,7 @@ class AutocompleteInteraction extends Interaction { }, }, }); - this.replied = true; + this.responded = true; } } From ba00b8373c4590b3c6522f2d313363887a40d55c Mon Sep 17 00:00:00 2001 From: SirH Date: Thu, 23 Sep 2021 10:00:48 -0400 Subject: [PATCH 17/50] fix: necessary properties and types --- src/structures/AutocompleteInteraction.js | 22 ++++++++++++++++++++++ typings/index.d.ts | 6 ++++++ 2 files changed, 28 insertions(+) diff --git a/src/structures/AutocompleteInteraction.js b/src/structures/AutocompleteInteraction.js index 226d06e77448..fc8e5407b80b 100644 --- a/src/structures/AutocompleteInteraction.js +++ b/src/structures/AutocompleteInteraction.js @@ -12,6 +12,19 @@ class AutocompleteInteraction extends Interaction { constructor(client, data) { super(client, data); + /** + * The channel this interaction was sent in + * @type {?TextBasedChannels} + * @name AutocompleteInteraction#channel + * @readonly + */ + + /** + * The id of the channel this interaction was sent in + * @type {Snowflake} + * @name AutocompleteInteraction#channelId + */ + /** * The invoked application command's id * @type {Snowflake} @@ -40,6 +53,15 @@ class AutocompleteInteraction extends Interaction { ); } + /** + * The invoked application command, if it was fetched before + * @type {?ApplicationCommand} + */ + get command() { + const id = this.commandId; + return this.guild?.commands.cache.get(id) ?? this.client.application.commands.cache.get(id) ?? null; + } + /** * Transforms an option received from the API. * @param {APIApplicationCommandOption} option The received option diff --git a/typings/index.d.ts b/typings/index.d.ts index f91c0f4ab200..cbb434929fec 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -558,6 +558,12 @@ export class CommandInteraction extends BaseCommandInteraction { } export class AutocompleteInteraction extends Interaction { + public readonly command: ApplicationCommand | ApplicationCommand<{ guild: GuildResolvable }> | null; + public readonly channel: TextBasedChannels | null; + public channelId: Snowflake; + public commandId: Snowflake; + public commandName: string; + public responded: boolean; public options: CommandInteractionOptionResolver; private transformOption(option: APIApplicationCommandOption): CommandInteractionOption; public respond(options: ApplicationCommandOptionChoice[]): Promise; From 73530915a7c982e2938472793225c1cc1d35c51b Mon Sep 17 00:00:00 2001 From: SirH Date: Thu, 23 Sep 2021 22:10:43 -0400 Subject: [PATCH 18/50] fix: export autocomplete interaction --- src/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.js b/src/index.js index 09916d9f4f87..d8eb3f4d769d 100644 --- a/src/index.js +++ b/src/index.js @@ -70,6 +70,7 @@ module.exports = { AnonymousGuild: require('./structures/AnonymousGuild'), Application: require('./structures/interfaces/Application'), ApplicationCommand: require('./structures/ApplicationCommand'), + AutocompleteInteraction: require('./structures/AutocompleteInteraction'), Base: require('./structures/Base'), BaseCommandInteraction: require('./structures/BaseCommandInteraction'), BaseGuild: require('./structures/BaseGuild'), From 4d597c1f6d0fd3bf72593742345803e45629a487 Mon Sep 17 00:00:00 2001 From: SirH Date: Sat, 25 Sep 2021 05:31:02 -0400 Subject: [PATCH 19/50] types: return never if non-autocomplete interaction uses focused getter --- typings/index.d.ts | 22 ++++++++++++++++------ typings/tests.ts | 2 +- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index cbb434929fec..569be51d249a 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -554,7 +554,7 @@ export abstract class Collector extends EventEmi } export class CommandInteraction extends BaseCommandInteraction { - public options: CommandInteractionOptionResolver; + public options: CommandInteractionOptionResolver; } export class AutocompleteInteraction extends Interaction { @@ -564,12 +564,14 @@ export class AutocompleteInteraction extends Interaction { public commandId: Snowflake; public commandName: string; public responded: boolean; - public options: CommandInteractionOptionResolver; + public options: CommandInteractionOptionResolver; private transformOption(option: APIApplicationCommandOption): CommandInteractionOption; public respond(options: ApplicationCommandOptionChoice[]): Promise; } -export class CommandInteractionOptionResolver { +export class CommandInteractionOptionResolver< + Type extends AutocompleteInteraction | ContextMenuInteraction | CommandInteraction, +> { public constructor(client: Client, options: CommandInteractionOption[], resolved: CommandInteractionResolvedData); public readonly client: Client; public readonly data: readonly CommandInteractionOption[]; @@ -623,12 +625,20 @@ export class CommandInteractionOptionResolver { ): NonNullable | null; public getMessage(name: string, required: true): NonNullable; public getMessage(name: string, required?: boolean): NonNullable | null; - public getFocused(getFull: true): ApplicationCommandOptionChoice; - public getFocused(getFull?: boolean): string | number; + public getFocused< + T extends InteractionOptionResolverReturn, + >(getFull: true): T; + public getFocused>( + getFull?: boolean, + ): T; } +export type InteractionOptionResolverReturn = T extends AllowedInteraction + ? ReturnType + : never; + export class ContextMenuInteraction extends BaseCommandInteraction { - public options: CommandInteractionOptionResolver; + public options: CommandInteractionOptionResolver; public targetId: Snowflake; public targetType: Exclude; private resolveContextMenuOptions(data: APIApplicationCommandInteractionData): CommandInteractionOption[]; diff --git a/typings/tests.ts b/typings/tests.ts index f4f52c067f56..1fde696c6b88 100644 --- a/typings/tests.ts +++ b/typings/tests.ts @@ -827,7 +827,7 @@ if (interaction.inGuild()) assertType(interaction.guildId); client.on('interactionCreate', async interaction => { if (interaction.isCommand()) { assertType(interaction); - assertType(interaction.options); + assertType>(interaction.options); assertType(interaction.options.data); const optionalOption = interaction.options.get('name'); From 98d92ca114fc46ce0ffa0f6e3785417b32bc942d Mon Sep 17 00:00:00 2001 From: SirH Date: Mon, 27 Sep 2021 18:49:41 -0400 Subject: [PATCH 20/50] fix: options equal function to compare with autocomplete --- src/structures/ApplicationCommand.js | 2 ++ typings/index.d.ts | 10 ++++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/structures/ApplicationCommand.js b/src/structures/ApplicationCommand.js index ba1bcf7e9372..6ecb1c32c954 100644 --- a/src/structures/ApplicationCommand.js +++ b/src/structures/ApplicationCommand.js @@ -182,6 +182,7 @@ class ApplicationCommand extends Base { command.name !== this.name || ('description' in command && command.description !== this.description) || ('version' in command && command.version !== this.version) || + ('autocomplete' in command && command.autocomplete !== this.autocomplete) || (commandType && commandType !== this.type) || // Future proof for options being nullable // TODO: remove ?? 0 on each when nullable @@ -237,6 +238,7 @@ class ApplicationCommand extends Base { option.name !== existing.name || optionType !== existing.type || option.description !== existing.description || + option.autocomplete !== existing.autocomplete || (option.required ?? (['SUB_COMMAND', 'SUB_COMMAND_GROUP'].includes(optionType) ? undefined : false)) !== existing.required || option.choices?.length !== existing.choices?.length || diff --git a/typings/index.d.ts b/typings/index.d.ts index 569be51d249a..826eb10af3ec 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -625,12 +625,10 @@ export class CommandInteractionOptionResolver< ): NonNullable | null; public getMessage(name: string, required: true): NonNullable; public getMessage(name: string, required?: boolean): NonNullable | null; - public getFocused< - T extends InteractionOptionResolverReturn, - >(getFull: true): T; - public getFocused>( - getFull?: boolean, - ): T; + public getFocused( + getFull: true, + ): InteractionOptionResolverReturn; + public getFocused(getFull?: boolean): InteractionOptionResolverReturn; } export type InteractionOptionResolverReturn = T extends AllowedInteraction From 689f461e053d80dc4b67bbd886db6a1694102a0b Mon Sep 17 00:00:00 2001 From: SirH Date: Wed, 22 Sep 2021 01:52:57 -0400 Subject: [PATCH 21/50] feat: add support for autocomplete interactions --- src/structures/AutocompleteInteraction.js | 26 +++++++++++++++++ src/structures/BaseCommandInteraction.js | 1 + .../CommandInteractionOptionResolver.js | 12 ++++++++ src/structures/Interaction.js | 11 +++++++ .../interfaces/InteractionResponses.js | 29 +++++++++++++++++++ src/util/Constants.js | 9 +++++- typings/enums.d.ts | 2 ++ typings/index.d.ts | 13 +++++++++ 8 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 src/structures/AutocompleteInteraction.js diff --git a/src/structures/AutocompleteInteraction.js b/src/structures/AutocompleteInteraction.js new file mode 100644 index 000000000000..9052120b59b0 --- /dev/null +++ b/src/structures/AutocompleteInteraction.js @@ -0,0 +1,26 @@ +'use strict'; + +const CommandInteractionOptionResolver = require('./CommandInteractionOptionResolver'); +const Interaction = require('./Interaction'); + +/** + * Represents a autocomplete interaction. + * @extends {Interaction} + */ +class AutocompleteInteraction extends Interaction { + constructor(client, data) { + super(client, data); + + /** + * The options passed to the command. + * @type {CommandInteractionOptionResolver} + */ + this.options = new CommandInteractionOptionResolver( + this.client, + data.data.options?.map(option => this.transformOption(option, data.data.resolved)) ?? [], + this.transformResolved(data.data.resolved ?? {}), + ); + } +} + +module.exports = AutocompleteInteraction; diff --git a/src/structures/BaseCommandInteraction.js b/src/structures/BaseCommandInteraction.js index ec6eb4fd7f5d..a461a5392acf 100644 --- a/src/structures/BaseCommandInteraction.js +++ b/src/structures/BaseCommandInteraction.js @@ -162,6 +162,7 @@ class BaseCommandInteraction extends Interaction { if ('value' in option) result.value = option.value; if ('options' in option) result.options = option.options.map(opt => this.transformOption(opt, resolved)); + if ('focused' in option) result.focused = option.focused; if (resolved) { const user = resolved.users?.[option.value]; diff --git a/src/structures/CommandInteractionOptionResolver.js b/src/structures/CommandInteractionOptionResolver.js index e74613f45a76..2f54d620615f 100644 --- a/src/structures/CommandInteractionOptionResolver.js +++ b/src/structures/CommandInteractionOptionResolver.js @@ -239,6 +239,18 @@ class CommandInteractionOptionResolver { const option = this._getTypedOption(name, '_MESSAGE', ['message'], required); return option?.message ?? null; } + + /** + * Gets a focused option. + * @param {name} name The name of the option. + * @param {boolean} [required=false] Whether to throw an error if the option is not found. + * @returns {?(string)} + * The value of the option, or null if not set and not required. + */ + getFocused(name, required = false) { + const option = this._getTypedOption(name, 'STRING', ['value'], required); + return option?.value ?? null; + } } module.exports = CommandInteractionOptionResolver; diff --git a/src/structures/Interaction.js b/src/structures/Interaction.js index 82fe70881a92..0edde4f039b1 100644 --- a/src/structures/Interaction.js +++ b/src/structures/Interaction.js @@ -136,6 +136,17 @@ class Interaction extends Base { return InteractionTypes[this.type] === InteractionTypes.APPLICATION_COMMAND && typeof this.targetId !== 'undefined'; } + /** + * Indicates whether this interaction is a {@link AutocompleteInteraction} + * @returns {boolean} + */ + isAutocomplete() { + return ( + InteractionTypes[this.type] === InteractionTypes.APPLICATION_COMMAND_AUTOCOMPLETE && + typeof this.targetId === 'undefined' + ); + } + /** * Indicates whether this interaction is a {@link MessageComponentInteraction}. * @returns {boolean} diff --git a/src/structures/interfaces/InteractionResponses.js b/src/structures/interfaces/InteractionResponses.js index 8a36d8204605..3a6fa0fe2727 100644 --- a/src/structures/interfaces/InteractionResponses.js +++ b/src/structures/interfaces/InteractionResponses.js @@ -218,6 +218,35 @@ class InteractionResponses { return options.fetchReply ? this.fetchReply() : undefined; } + /** + * Sends results for the autocomplete of this interaction. + * @param {InteractionResultOptions} options The options for the autocomplete + * @returns {Promise} + * @example + * // respond to autocomplete interaction + * interaction.autocomplete({ + * options: [ + * { + * name: 'Option 1', + * value: 'option1', + * }, + * ], + * }) + * .then(console.log) + * .catch(console.error); + */ + async result(options) { + if (this.replied) throw new Error('INTERACTION_ALREADY_REPLIED'); + + await this.client.api.interactions(this.id, this.token).callback.post({ + data: { + type: InteractionResponseTypes.APPLICATION_COMMAND_AUTOCOMPLETE_RESULT, + data: options, + }, + }); + this.replied = true; + } + static applyToClass(structure, ignore = []) { const props = [ 'deferReply', diff --git a/src/util/Constants.js b/src/util/Constants.js index a71d64fa1aec..2ecd993bf62a 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -966,7 +966,13 @@ exports.ApplicationCommandPermissionTypes = createEnum([null, 'ROLE', 'USER']); * @typedef {string} InteractionType * @see {@link https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-type} */ -exports.InteractionTypes = createEnum([null, 'PING', 'APPLICATION_COMMAND', 'MESSAGE_COMPONENT']); +exports.InteractionTypes = createEnum([ + null, + 'PING', + 'APPLICATION_COMMAND', + 'MESSAGE_COMPONENT', + 'APPLICATION_COMMAND_AUTOCOMPLETE', +]); /** * The type of an interaction response: @@ -987,6 +993,7 @@ exports.InteractionResponseTypes = createEnum([ 'DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE', 'DEFERRED_MESSAGE_UPDATE', 'UPDATE_MESSAGE', + 'APPLICATION_COMMAND_AUTOCOMPLETE_RESULT', ]); /* eslint-enable max-len */ diff --git a/typings/enums.d.ts b/typings/enums.d.ts index 1a27f547026b..515409c330d8 100644 --- a/typings/enums.d.ts +++ b/typings/enums.d.ts @@ -66,12 +66,14 @@ export const enum InteractionResponseTypes { DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE = 5, DEFERRED_MESSAGE_UPDATE = 6, UPDATE_MESSAGE = 7, + APPLICATION_COMMAND_AUTOCOMPLETE_RESULT = 8, } export const enum InteractionTypes { PING = 1, APPLICATION_COMMAND = 2, MESSAGE_COMPONENT = 3, + APPLICATION_COMMAND_AUTOCOMPLETE = 4, } export const enum InviteTargetType { diff --git a/typings/index.d.ts b/typings/index.d.ts index 2fc8b099d193..d0e7ea5ee9f3 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -582,6 +582,11 @@ export class CommandInteraction extends BaseCommandInteraction { public options: CommandInteractionOptionResolver; } +export class AutocompleteInteraction extends Interaction { + public options: CommandInteractionOptionResolver; + public result: (name: string, required: boolean) => Promise; +} + export class CommandInteractionOptionResolver { private constructor(client: Client, options: CommandInteractionOption[], resolved: CommandInteractionResolvedData); public readonly client: Client; @@ -636,6 +641,7 @@ export class CommandInteractionOptionResolver { ): NonNullable | null; public getMessage(name: string, required: true): NonNullable; public getMessage(name: string, required?: boolean): NonNullable | null; + public getFocused(name: string, require?: boolean): string | null; } export class ContextMenuInteraction extends BaseCommandInteraction { @@ -1064,6 +1070,7 @@ export class Interaction extends Base { }; public isButton(): this is ButtonInteraction; public isCommand(): this is CommandInteraction; + public isAutocomplete(): this is AutocompleteInteraction; public isContextMenu(): this is ContextMenuInteraction; public isMessageComponent(): this is MessageComponentInteraction; public isSelectMenu(): this is SelectMenuInteraction; @@ -3560,6 +3567,8 @@ export interface CommandInteractionOption { name: string; type: ApplicationCommandOptionType; value?: string | number | boolean; + autocomplete?: boolean; + focused?: boolean; options?: CommandInteractionOption[]; user?: User; member?: GuildMember | APIInteractionDataResolvedGuildMember; @@ -4195,6 +4204,10 @@ export interface InteractionUpdateOptions extends MessageEditOptions { fetchReply?: boolean; } +export interface InteractionResultOptions { + options: CommandInteractionOption[]; +} + export type IntentsString = | 'GUILDS' | 'GUILD_MEMBERS' From a46bddc1f6b9f2f55170ca73b380a7bbb60b28ba Mon Sep 17 00:00:00 2001 From: SirH Date: Wed, 22 Sep 2021 03:58:32 -0400 Subject: [PATCH 22/50] fix: redid some bits of the implementation --- src/client/actions/InteractionCreate.js | 4 +++ src/structures/AutocompleteInteraction.js | 34 +++++++++++++++++-- .../CommandInteractionOptionResolver.js | 14 ++++---- src/structures/Interaction.js | 5 +-- .../interfaces/InteractionResponses.js | 29 ---------------- typings/index.d.ts | 10 +++--- 6 files changed, 49 insertions(+), 47 deletions(-) diff --git a/src/client/actions/InteractionCreate.js b/src/client/actions/InteractionCreate.js index eeb68c0bcc9b..ddbc097a695f 100644 --- a/src/client/actions/InteractionCreate.js +++ b/src/client/actions/InteractionCreate.js @@ -1,6 +1,7 @@ 'use strict'; const Action = require('./Action'); +const AutocompleteInteraction = require('../../structures/AutocompleteInteraction'); const ButtonInteraction = require('../../structures/ButtonInteraction'); const CommandInteraction = require('../../structures/CommandInteraction'); const ContextMenuInteraction = require('../../structures/ContextMenuInteraction'); @@ -51,6 +52,9 @@ class InteractionCreateAction extends Action { return; } break; + case InteractionTypes.APPLICATION_COMMAND_AUTOCOMPLETE: + InteractionType = AutocompleteInteraction; + break; default: client.emit(Events.DEBUG, `[INTERACTION] Received interaction with unknown type: ${data.type}`); return; diff --git a/src/structures/AutocompleteInteraction.js b/src/structures/AutocompleteInteraction.js index 9052120b59b0..4f38bc790272 100644 --- a/src/structures/AutocompleteInteraction.js +++ b/src/structures/AutocompleteInteraction.js @@ -1,13 +1,14 @@ 'use strict'; +const BaseCommandInteraction = require('./BaseCommandInteraction'); const CommandInteractionOptionResolver = require('./CommandInteractionOptionResolver'); -const Interaction = require('./Interaction'); +const { InteractionResponseTypes } = require('../util/Constants'); /** * Represents a autocomplete interaction. * @extends {Interaction} */ -class AutocompleteInteraction extends Interaction { +class AutocompleteInteraction extends BaseCommandInteraction { constructor(client, data) { super(client, data); @@ -21,6 +22,35 @@ class AutocompleteInteraction extends Interaction { this.transformResolved(data.data.resolved ?? {}), ); } + + /** + * Sends results for the autocomplete of this interaction. + * @param {InteractionResultOptions} options The options for the autocomplete + * @returns {Promise} + * @example + * // respond to autocomplete interaction + * interaction.result({ + * options: [ + * { + * name: 'Option 1', + * value: 'option1', + * }, + * ], + * }) + * .then(console.log) + * .catch(console.error); + */ + async result(options) { + if (this.replied) throw new Error('INTERACTION_ALREADY_REPLIED'); + + await this.client.api.interactions(this.id, this.token).callback.post({ + data: { + type: InteractionResponseTypes.APPLICATION_COMMAND_AUTOCOMPLETE_RESULT, + data: options, + }, + }); + this.replied = true; + } } module.exports = AutocompleteInteraction; diff --git a/src/structures/CommandInteractionOptionResolver.js b/src/structures/CommandInteractionOptionResolver.js index 2f54d620615f..50f3298d136d 100644 --- a/src/structures/CommandInteractionOptionResolver.js +++ b/src/structures/CommandInteractionOptionResolver.js @@ -241,15 +241,17 @@ class CommandInteractionOptionResolver { } /** - * Gets a focused option. - * @param {name} name The name of the option. + * Gets the focused option. * @param {boolean} [required=false] Whether to throw an error if the option is not found. - * @returns {?(string)} + * @returns {?(string|number)} * The value of the option, or null if not set and not required. */ - getFocused(name, required = false) { - const option = this._getTypedOption(name, 'STRING', ['value'], required); - return option?.value ?? null; + getFocused(required = false) { + const focusedOption = this._hoistedOptions.find(option => option.focused); + if (required && !focusedOption) { + throw new TypeError('AUTOCOMPLETE_INTERACTION_OPTION_NO_FOCUSED_OPTION'); + } + return focusedOption?.value ?? null; } } diff --git a/src/structures/Interaction.js b/src/structures/Interaction.js index 0edde4f039b1..61dd95cba1e0 100644 --- a/src/structures/Interaction.js +++ b/src/structures/Interaction.js @@ -141,10 +141,7 @@ class Interaction extends Base { * @returns {boolean} */ isAutocomplete() { - return ( - InteractionTypes[this.type] === InteractionTypes.APPLICATION_COMMAND_AUTOCOMPLETE && - typeof this.targetId === 'undefined' - ); + return InteractionTypes[this.type] === InteractionTypes.APPLICATION_COMMAND_AUTOCOMPLETE; } /** diff --git a/src/structures/interfaces/InteractionResponses.js b/src/structures/interfaces/InteractionResponses.js index 3a6fa0fe2727..8a36d8204605 100644 --- a/src/structures/interfaces/InteractionResponses.js +++ b/src/structures/interfaces/InteractionResponses.js @@ -218,35 +218,6 @@ class InteractionResponses { return options.fetchReply ? this.fetchReply() : undefined; } - /** - * Sends results for the autocomplete of this interaction. - * @param {InteractionResultOptions} options The options for the autocomplete - * @returns {Promise} - * @example - * // respond to autocomplete interaction - * interaction.autocomplete({ - * options: [ - * { - * name: 'Option 1', - * value: 'option1', - * }, - * ], - * }) - * .then(console.log) - * .catch(console.error); - */ - async result(options) { - if (this.replied) throw new Error('INTERACTION_ALREADY_REPLIED'); - - await this.client.api.interactions(this.id, this.token).callback.post({ - data: { - type: InteractionResponseTypes.APPLICATION_COMMAND_AUTOCOMPLETE_RESULT, - data: options, - }, - }); - this.replied = true; - } - static applyToClass(structure, ignore = []) { const props = [ 'deferReply', diff --git a/typings/index.d.ts b/typings/index.d.ts index d0e7ea5ee9f3..34fb8f6c087f 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -584,7 +584,7 @@ export class CommandInteraction extends BaseCommandInteraction { export class AutocompleteInteraction extends Interaction { public options: CommandInteractionOptionResolver; - public result: (name: string, required: boolean) => Promise; + public result: (options: InteractionResultOptions) => Promise; } export class CommandInteractionOptionResolver { @@ -641,7 +641,7 @@ export class CommandInteractionOptionResolver { ): NonNullable | null; public getMessage(name: string, required: true): NonNullable; public getMessage(name: string, required?: boolean): NonNullable | null; - public getFocused(name: string, require?: boolean): string | null; + public getFocused(require?: boolean): string | number | null; } export class ContextMenuInteraction extends BaseCommandInteraction { @@ -3567,8 +3567,8 @@ export interface CommandInteractionOption { name: string; type: ApplicationCommandOptionType; value?: string | number | boolean; - autocomplete?: boolean; focused?: boolean; + autocomplete?: boolean; options?: CommandInteractionOption[]; user?: User; member?: GuildMember | APIInteractionDataResolvedGuildMember; @@ -4204,9 +4204,7 @@ export interface InteractionUpdateOptions extends MessageEditOptions { fetchReply?: boolean; } -export interface InteractionResultOptions { - options: CommandInteractionOption[]; -} +export type InteractionResultOptions = CommandInteractionOption[]; export type IntentsString = | 'GUILDS' From b876a3574a87089e756c0744a828837f204eed6c Mon Sep 17 00:00:00 2001 From: SirH Date: Wed, 22 Sep 2021 04:17:51 -0400 Subject: [PATCH 23/50] types: autocomplete extends --- src/structures/AutocompleteInteraction.js | 2 +- typings/index.d.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/structures/AutocompleteInteraction.js b/src/structures/AutocompleteInteraction.js index 4f38bc790272..eea57189ba15 100644 --- a/src/structures/AutocompleteInteraction.js +++ b/src/structures/AutocompleteInteraction.js @@ -6,7 +6,7 @@ const { InteractionResponseTypes } = require('../util/Constants'); /** * Represents a autocomplete interaction. - * @extends {Interaction} + * @extends {BaseCommandInteraction} */ class AutocompleteInteraction extends BaseCommandInteraction { constructor(client, data) { diff --git a/typings/index.d.ts b/typings/index.d.ts index 34fb8f6c087f..55b5156e95cc 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -582,7 +582,7 @@ export class CommandInteraction extends BaseCommandInteraction { public options: CommandInteractionOptionResolver; } -export class AutocompleteInteraction extends Interaction { +export class AutocompleteInteraction extends BaseCommandInteraction { public options: CommandInteractionOptionResolver; public result: (options: InteractionResultOptions) => Promise; } From d9f3830fc4b973bd65a8ca8f71f1cd89ef097655 Mon Sep 17 00:00:00 2001 From: SirH Date: Wed, 22 Sep 2021 10:14:05 -0400 Subject: [PATCH 24/50] fix: indentation and grammar --- src/structures/AutocompleteInteraction.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/structures/AutocompleteInteraction.js b/src/structures/AutocompleteInteraction.js index eea57189ba15..d6fae77516f2 100644 --- a/src/structures/AutocompleteInteraction.js +++ b/src/structures/AutocompleteInteraction.js @@ -5,7 +5,7 @@ const CommandInteractionOptionResolver = require('./CommandInteractionOptionReso const { InteractionResponseTypes } = require('../util/Constants'); /** - * Represents a autocomplete interaction. + * Represents an autocomplete interaction. * @extends {BaseCommandInteraction} */ class AutocompleteInteraction extends BaseCommandInteraction { @@ -38,7 +38,7 @@ class AutocompleteInteraction extends BaseCommandInteraction { * ], * }) * .then(console.log) - * .catch(console.error); + * .catch(console.error); */ async result(options) { if (this.replied) throw new Error('INTERACTION_ALREADY_REPLIED'); From 7a27aaa52af8e0debbb4624d1f0705f53b885797 Mon Sep 17 00:00:00 2001 From: SirH Date: Wed, 22 Sep 2021 10:27:57 -0400 Subject: [PATCH 25/50] fix: example for result method --- src/structures/AutocompleteInteraction.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/structures/AutocompleteInteraction.js b/src/structures/AutocompleteInteraction.js index d6fae77516f2..8947997a2242 100644 --- a/src/structures/AutocompleteInteraction.js +++ b/src/structures/AutocompleteInteraction.js @@ -29,14 +29,12 @@ class AutocompleteInteraction extends BaseCommandInteraction { * @returns {Promise} * @example * // respond to autocomplete interaction - * interaction.result({ - * options: [ - * { + * interaction.result([ + * { * name: 'Option 1', * value: 'option1', - * }, - * ], - * }) + * }, + * ]) * .then(console.log) * .catch(console.error); */ From 1d642b648a96539e6f7db6098cd0c972691d1ed4 Mon Sep 17 00:00:00 2001 From: SirH Date: Wed, 22 Sep 2021 10:31:26 -0400 Subject: [PATCH 26/50] types: readjust result to consistent typing --- 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 55b5156e95cc..9d85476ae458 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -584,7 +584,7 @@ export class CommandInteraction extends BaseCommandInteraction { export class AutocompleteInteraction extends BaseCommandInteraction { public options: CommandInteractionOptionResolver; - public result: (options: InteractionResultOptions) => Promise; + public result(options: InteractionResultOptions): Promise; } export class CommandInteractionOptionResolver { From f4c8d241b206d432552516be4d7a51a661d56a4f Mon Sep 17 00:00:00 2001 From: SirH Date: Wed, 22 Sep 2021 11:17:11 -0400 Subject: [PATCH 27/50] types: update options for result method --- 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 9d85476ae458..856ed52635eb 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -4204,7 +4204,7 @@ export interface InteractionUpdateOptions extends MessageEditOptions { fetchReply?: boolean; } -export type InteractionResultOptions = CommandInteractionOption[]; +export type InteractionResultOptions = ApplicationCommandOptionChoice[]; export type IntentsString = | 'GUILDS' From 4f729434fceca1a60ec25df785b20f1a01e980df Mon Sep 17 00:00:00 2001 From: SirH Date: Wed, 22 Sep 2021 11:44:08 -0400 Subject: [PATCH 28/50] types: add missing types --- typings/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/typings/index.d.ts b/typings/index.d.ts index 856ed52635eb..a300fa4a93ed 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -3107,6 +3107,7 @@ export interface BaseApplicationCommandOptionsData { name: string; description: string; required?: boolean; + autocomplete?: boolean; } export interface UserApplicationCommandData extends BaseApplicationCommandData { From 9a5974499a5586b33cae16c929f138d2c0c62539 Mon Sep 17 00:00:00 2001 From: SirH Date: Wed, 22 Sep 2021 12:01:35 -0400 Subject: [PATCH 29/50] fix: grammar and formatting --- src/structures/AutocompleteInteraction.js | 2 +- src/structures/CommandInteractionOptionResolver.js | 3 +-- src/structures/Interaction.js | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/structures/AutocompleteInteraction.js b/src/structures/AutocompleteInteraction.js index 8947997a2242..ad02639c8a01 100644 --- a/src/structures/AutocompleteInteraction.js +++ b/src/structures/AutocompleteInteraction.js @@ -13,7 +13,7 @@ class AutocompleteInteraction extends BaseCommandInteraction { super(client, data); /** - * The options passed to the command. + * The options passed to the command * @type {CommandInteractionOptionResolver} */ this.options = new CommandInteractionOptionResolver( diff --git a/src/structures/CommandInteractionOptionResolver.js b/src/structures/CommandInteractionOptionResolver.js index 50f3298d136d..67c9ee350fa1 100644 --- a/src/structures/CommandInteractionOptionResolver.js +++ b/src/structures/CommandInteractionOptionResolver.js @@ -243,8 +243,7 @@ class CommandInteractionOptionResolver { /** * Gets the focused option. * @param {boolean} [required=false] Whether to throw an error if the option is not found. - * @returns {?(string|number)} - * The value of the option, or null if not set and not required. + * @returns {?(string|number)} The value of the option, or null if not set and not required. */ getFocused(required = false) { const focusedOption = this._hoistedOptions.find(option => option.focused); diff --git a/src/structures/Interaction.js b/src/structures/Interaction.js index 61dd95cba1e0..4a87af1516cf 100644 --- a/src/structures/Interaction.js +++ b/src/structures/Interaction.js @@ -137,7 +137,7 @@ class Interaction extends Base { } /** - * Indicates whether this interaction is a {@link AutocompleteInteraction} + * Indicates whether this interaction is an {@link AutocompleteInteraction} * @returns {boolean} */ isAutocomplete() { From cc29956964ac8b85296bfa768580940e5b00c38d Mon Sep 17 00:00:00 2001 From: SirH Date: Wed, 22 Sep 2021 12:20:16 -0400 Subject: [PATCH 30/50] fix: transformCommand method allows autocomplete --- src/structures/ApplicationCommand.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/structures/ApplicationCommand.js b/src/structures/ApplicationCommand.js index b6c99a443587..244163b8b8d7 100644 --- a/src/structures/ApplicationCommand.js +++ b/src/structures/ApplicationCommand.js @@ -332,6 +332,7 @@ class ApplicationCommand extends Base { description: option.description, required: option.required ?? (stringType === 'SUB_COMMAND' || stringType === 'SUB_COMMAND_GROUP' ? undefined : false), + autocomplete: option.autocomplete, choices: option.choices, options: option.options?.map(o => this.transformOption(o, received)), [channelTypesKey]: received From 02cb30368f1f06ff672db1104fb5bf4bd55e5658 Mon Sep 17 00:00:00 2001 From: SirH Date: Wed, 22 Sep 2021 12:31:11 -0400 Subject: [PATCH 31/50] fix: result method's callback --- src/structures/AutocompleteInteraction.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/structures/AutocompleteInteraction.js b/src/structures/AutocompleteInteraction.js index ad02639c8a01..fb109cb82283 100644 --- a/src/structures/AutocompleteInteraction.js +++ b/src/structures/AutocompleteInteraction.js @@ -44,7 +44,9 @@ class AutocompleteInteraction extends BaseCommandInteraction { await this.client.api.interactions(this.id, this.token).callback.post({ data: { type: InteractionResponseTypes.APPLICATION_COMMAND_AUTOCOMPLETE_RESULT, - data: options, + data: { + choices: options, + }, }, }); this.replied = true; From 4cdd056dbcb3a5f1d9e01955c63138358029c6d6 Mon Sep 17 00:00:00 2001 From: SirH Date: Wed, 22 Sep 2021 13:36:51 -0400 Subject: [PATCH 32/50] fix: getFocused method return --- src/structures/CommandInteractionOptionResolver.js | 6 +++--- typings/index.d.ts | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/structures/CommandInteractionOptionResolver.js b/src/structures/CommandInteractionOptionResolver.js index 67c9ee350fa1..86b04cc79db9 100644 --- a/src/structures/CommandInteractionOptionResolver.js +++ b/src/structures/CommandInteractionOptionResolver.js @@ -242,15 +242,15 @@ class CommandInteractionOptionResolver { /** * Gets the focused option. - * @param {boolean} [required=false] Whether to throw an error if the option is not found. - * @returns {?(string|number)} The value of the option, or null if not set and not required. + * @param {boolean} [required=false] Whether to throw an error if the option is not found + * @returns {?(string|number)} The value of the option, or null if not set and not required */ getFocused(required = false) { const focusedOption = this._hoistedOptions.find(option => option.focused); if (required && !focusedOption) { throw new TypeError('AUTOCOMPLETE_INTERACTION_OPTION_NO_FOCUSED_OPTION'); } - return focusedOption?.value ?? null; + return focusedOption ?? null; } } diff --git a/typings/index.d.ts b/typings/index.d.ts index a300fa4a93ed..7d3da7917ec4 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -641,7 +641,8 @@ export class CommandInteractionOptionResolver { ): NonNullable | null; public getMessage(name: string, required: true): NonNullable; public getMessage(name: string, required?: boolean): NonNullable | null; - public getFocused(require?: boolean): string | number | null; + public getFocused(require: true): ApplicationCommandOptionChoice; + public getFocused(require?: boolean): ApplicationCommandOptionChoice | null; } export class ContextMenuInteraction extends BaseCommandInteraction { From b899cfdfed2a46ee772d92fe0ab9637099e52d7b Mon Sep 17 00:00:00 2001 From: SirH Date: Wed, 22 Sep 2021 14:31:32 -0400 Subject: [PATCH 33/50] types: replace unecessary type --- src/structures/AutocompleteInteraction.js | 2 +- typings/index.d.ts | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/structures/AutocompleteInteraction.js b/src/structures/AutocompleteInteraction.js index fb109cb82283..ffbf0b40c88a 100644 --- a/src/structures/AutocompleteInteraction.js +++ b/src/structures/AutocompleteInteraction.js @@ -25,7 +25,7 @@ class AutocompleteInteraction extends BaseCommandInteraction { /** * Sends results for the autocomplete of this interaction. - * @param {InteractionResultOptions} options The options for the autocomplete + * @param {ApplicationCommandOptionChoice[]} options The options for the autocomplete * @returns {Promise} * @example * // respond to autocomplete interaction diff --git a/typings/index.d.ts b/typings/index.d.ts index 7d3da7917ec4..c0f5005b9130 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -584,7 +584,7 @@ export class CommandInteraction extends BaseCommandInteraction { export class AutocompleteInteraction extends BaseCommandInteraction { public options: CommandInteractionOptionResolver; - public result(options: InteractionResultOptions): Promise; + public result(options: ApplicationCommandOptionChoice[]): Promise; } export class CommandInteractionOptionResolver { @@ -4206,8 +4206,6 @@ export interface InteractionUpdateOptions extends MessageEditOptions { fetchReply?: boolean; } -export type InteractionResultOptions = ApplicationCommandOptionChoice[]; - export type IntentsString = | 'GUILDS' | 'GUILD_MEMBERS' From 7d5d39c863e63b769dd383b7143f42791505880d Mon Sep 17 00:00:00 2001 From: SirH Date: Thu, 23 Sep 2021 07:29:35 -0400 Subject: [PATCH 34/50] fix: definitions and methods for autocomplete interaction --- src/structures/ApplicationCommand.js | 2 + src/structures/AutocompleteInteraction.js | 45 ++++++++++++++++--- src/structures/BaseCommandInteraction.js | 2 +- .../CommandInteractionOptionResolver.js | 13 +++--- typings/index.d.ts | 9 ++-- 5 files changed, 53 insertions(+), 18 deletions(-) diff --git a/src/structures/ApplicationCommand.js b/src/structures/ApplicationCommand.js index 244163b8b8d7..7260fe63052e 100644 --- a/src/structures/ApplicationCommand.js +++ b/src/structures/ApplicationCommand.js @@ -140,6 +140,7 @@ class ApplicationCommand extends Base { * @property {ApplicationCommandOptionType|number} type The type of the option * @property {string} name The name of the option * @property {string} description The description of the option + * @property {boolean} [autocomplete] Whether the option is an autocomplete option * @property {boolean} [required] Whether the option is required * @property {ApplicationCommandOptionChoice[]} [choices] The choices of the option for the user to pick from * @property {ApplicationCommandOptionData[]} [options] Additional options if this option is a subcommand (group) @@ -303,6 +304,7 @@ class ApplicationCommand extends Base { * @property {string} name The name of the option * @property {string} description The description of the option * @property {boolean} [required] Whether the option is required + * @property {boolean} [autocomplete] Whether the option is an autocomplete option * @property {ApplicationCommandOptionChoice[]} [choices] The choices of the option for the user to pick from * @property {ApplicationCommandOption[]} [options] Additional options if this option is a subcommand (group) * @property {ChannelType[]} [channelTypes] When the option type is channel, diff --git a/src/structures/AutocompleteInteraction.js b/src/structures/AutocompleteInteraction.js index ffbf0b40c88a..8c5b77cca9df 100644 --- a/src/structures/AutocompleteInteraction.js +++ b/src/structures/AutocompleteInteraction.js @@ -1,14 +1,14 @@ 'use strict'; -const BaseCommandInteraction = require('./BaseCommandInteraction'); const CommandInteractionOptionResolver = require('./CommandInteractionOptionResolver'); -const { InteractionResponseTypes } = require('../util/Constants'); +const Interaction = require('./Interaction'); +const { InteractionResponseTypes, ApplicationCommandOptionTypes } = require('../util/Constants'); /** * Represents an autocomplete interaction. - * @extends {BaseCommandInteraction} + * @extends {Interaction} */ -class AutocompleteInteraction extends BaseCommandInteraction { +class AutocompleteInteraction extends Interaction { constructor(client, data) { super(client, data); @@ -19,17 +19,50 @@ class AutocompleteInteraction extends BaseCommandInteraction { this.options = new CommandInteractionOptionResolver( this.client, data.data.options?.map(option => this.transformOption(option, data.data.resolved)) ?? [], - this.transformResolved(data.data.resolved ?? {}), ); } + /** + * Transforms an option received from the API. + * @param {APIApplicationCommandOption} option The received option + * @param {APIInteractionDataResolved} resolved The resolved interaction data + * @returns {CommandInteractionOption} + * @private + */ + transformOption(option, resolved) { + const result = { + name: option.name, + type: ApplicationCommandOptionTypes[option.type], + }; + + if ('value' in option) result.value = option.value; + if ('options' in option) result.options = option.options.map(opt => this.transformOption(opt, resolved)); + if ('focused' in option) result.focused = option.focused; + + if (resolved) { + const user = resolved.users?.[option.value]; + if (user) result.user = this.client.users._add(user); + + const member = resolved.members?.[option.value]; + if (member) result.member = this.guild?.members._add({ user, ...member }) ?? member; + + const channel = resolved.channels?.[option.value]; + if (channel) result.channel = this.client.channels._add(channel, this.guild) ?? channel; + + const role = resolved.roles?.[option.value]; + if (role) result.role = this.guild?.roles._add(role) ?? role; + } + + return result; + } + /** * Sends results for the autocomplete of this interaction. * @param {ApplicationCommandOptionChoice[]} options The options for the autocomplete * @returns {Promise} * @example * // respond to autocomplete interaction - * interaction.result([ + * interaction.sendResult([ * { * name: 'Option 1', * value: 'option1', diff --git a/src/structures/BaseCommandInteraction.js b/src/structures/BaseCommandInteraction.js index a461a5392acf..dedf65dcf040 100644 --- a/src/structures/BaseCommandInteraction.js +++ b/src/structures/BaseCommandInteraction.js @@ -138,6 +138,7 @@ class BaseCommandInteraction extends Interaction { * @typedef {Object} CommandInteractionOption * @property {string} name The name of the option * @property {ApplicationCommandOptionType} type The type of the option + * @property {boolean} [autocomplete] Whether the option is an autocomplete option * @property {string|number|boolean} [value] The value of the option * @property {CommandInteractionOption[]} [options] Additional options if this option is a * subcommand (group) @@ -162,7 +163,6 @@ class BaseCommandInteraction extends Interaction { if ('value' in option) result.value = option.value; if ('options' in option) result.options = option.options.map(opt => this.transformOption(opt, resolved)); - if ('focused' in option) result.focused = option.focused; if (resolved) { const user = resolved.users?.[option.value]; diff --git a/src/structures/CommandInteractionOptionResolver.js b/src/structures/CommandInteractionOptionResolver.js index 86b04cc79db9..2f7634e5dda6 100644 --- a/src/structures/CommandInteractionOptionResolver.js +++ b/src/structures/CommandInteractionOptionResolver.js @@ -242,15 +242,14 @@ class CommandInteractionOptionResolver { /** * Gets the focused option. - * @param {boolean} [required=false] Whether to throw an error if the option is not found - * @returns {?(string|number)} The value of the option, or null if not set and not required + * @param {boolean} [getFull=false] Whether to throw an error if the option is not found + * @returns {string|number|ApplicationCommandOptionChoice} + * The value of the option, or the whole option if getFull is true */ - getFocused(required = false) { + getFocused(getFull = false) { const focusedOption = this._hoistedOptions.find(option => option.focused); - if (required && !focusedOption) { - throw new TypeError('AUTOCOMPLETE_INTERACTION_OPTION_NO_FOCUSED_OPTION'); - } - return focusedOption ?? null; + if (!focusedOption) throw new TypeError('AUTOCOMPLETE_INTERACTION_OPTION_NO_FOCUSED_OPTION'); + return getFull ? focusedOption : focusedOption.value; } } diff --git a/typings/index.d.ts b/typings/index.d.ts index c0f5005b9130..5da6710f5269 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -582,9 +582,10 @@ export class CommandInteraction extends BaseCommandInteraction { public options: CommandInteractionOptionResolver; } -export class AutocompleteInteraction extends BaseCommandInteraction { +export class AutocompleteInteraction extends Interaction { public options: CommandInteractionOptionResolver; - public result(options: ApplicationCommandOptionChoice[]): Promise; + private transformOption(option: APIApplicationCommandOption, resolved: null): CommandInteractionOption; + public sendResult(options: ApplicationCommandOptionChoice[]): Promise; } export class CommandInteractionOptionResolver { @@ -641,8 +642,8 @@ export class CommandInteractionOptionResolver { ): NonNullable | null; public getMessage(name: string, required: true): NonNullable; public getMessage(name: string, required?: boolean): NonNullable | null; - public getFocused(require: true): ApplicationCommandOptionChoice; - public getFocused(require?: boolean): ApplicationCommandOptionChoice | null; + public getFocused(getFull: true): ApplicationCommandOptionChoice; + public getFocused(getFull?: boolean): string | number; } export class ContextMenuInteraction extends BaseCommandInteraction { From 1dc4efe1719294ef7bd5f0aa787957abcb76a667 Mon Sep 17 00:00:00 2001 From: SirH Date: Thu, 23 Sep 2021 08:19:50 -0400 Subject: [PATCH 35/50] fix: inconsistencies and methods --- src/errors/Messages.js | 1 + src/structures/AutocompleteInteraction.js | 23 ++++--------------- .../CommandInteractionOptionResolver.js | 2 +- typings/index.d.ts | 4 ++-- 4 files changed, 8 insertions(+), 22 deletions(-) diff --git a/src/errors/Messages.js b/src/errors/Messages.js index affb80fa8426..61ee49484bc7 100644 --- a/src/errors/Messages.js +++ b/src/errors/Messages.js @@ -142,6 +142,7 @@ const Messages = { `Required option "${name}" is of type: ${type}; expected a non-empty value.`, COMMAND_INTERACTION_OPTION_NO_SUB_COMMAND: 'No subcommand specified for interaction.', COMMAND_INTERACTION_OPTION_NO_SUB_COMMAND_GROUP: 'No subcommand group specified for interaction.', + AUTOCOMPLETE_INTERACTION_OPTION_NO_FOCUSED_OPTION: 'No focused option for autocomplete interaction.', INVITE_MISSING_SCOPES: 'At least one valid scope must be provided for the invite', diff --git a/src/structures/AutocompleteInteraction.js b/src/structures/AutocompleteInteraction.js index 8c5b77cca9df..5b0e86a7513a 100644 --- a/src/structures/AutocompleteInteraction.js +++ b/src/structures/AutocompleteInteraction.js @@ -25,34 +25,19 @@ class AutocompleteInteraction extends Interaction { /** * Transforms an option received from the API. * @param {APIApplicationCommandOption} option The received option - * @param {APIInteractionDataResolved} resolved The resolved interaction data * @returns {CommandInteractionOption} * @private */ - transformOption(option, resolved) { + transformOption(option) { const result = { name: option.name, type: ApplicationCommandOptionTypes[option.type], }; if ('value' in option) result.value = option.value; - if ('options' in option) result.options = option.options.map(opt => this.transformOption(opt, resolved)); + if ('options' in option) result.options = option.options.map(opt => this.transformOption(opt)); if ('focused' in option) result.focused = option.focused; - if (resolved) { - const user = resolved.users?.[option.value]; - if (user) result.user = this.client.users._add(user); - - const member = resolved.members?.[option.value]; - if (member) result.member = this.guild?.members._add({ user, ...member }) ?? member; - - const channel = resolved.channels?.[option.value]; - if (channel) result.channel = this.client.channels._add(channel, this.guild) ?? channel; - - const role = resolved.roles?.[option.value]; - if (role) result.role = this.guild?.roles._add(role) ?? role; - } - return result; } @@ -62,7 +47,7 @@ class AutocompleteInteraction extends Interaction { * @returns {Promise} * @example * // respond to autocomplete interaction - * interaction.sendResult([ + * interaction.respond([ * { * name: 'Option 1', * value: 'option1', @@ -71,7 +56,7 @@ class AutocompleteInteraction extends Interaction { * .then(console.log) * .catch(console.error); */ - async result(options) { + async respond(options) { if (this.replied) throw new Error('INTERACTION_ALREADY_REPLIED'); await this.client.api.interactions(this.id, this.token).callback.post({ diff --git a/src/structures/CommandInteractionOptionResolver.js b/src/structures/CommandInteractionOptionResolver.js index 2f7634e5dda6..c83fd8e2f00e 100644 --- a/src/structures/CommandInteractionOptionResolver.js +++ b/src/structures/CommandInteractionOptionResolver.js @@ -242,7 +242,7 @@ class CommandInteractionOptionResolver { /** * Gets the focused option. - * @param {boolean} [getFull=false] Whether to throw an error if the option is not found + * @param {boolean} [getFull=false] Whether to get the full option object * @returns {string|number|ApplicationCommandOptionChoice} * The value of the option, or the whole option if getFull is true */ diff --git a/typings/index.d.ts b/typings/index.d.ts index 5da6710f5269..6ab973e73c00 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -584,8 +584,8 @@ export class CommandInteraction extends BaseCommandInteraction { export class AutocompleteInteraction extends Interaction { public options: CommandInteractionOptionResolver; - private transformOption(option: APIApplicationCommandOption, resolved: null): CommandInteractionOption; - public sendResult(options: ApplicationCommandOptionChoice[]): Promise; + private transformOption(option: APIApplicationCommandOption): CommandInteractionOption; + public respond(options: ApplicationCommandOptionChoice[]): Promise; } export class CommandInteractionOptionResolver { From e0286e9359fcacec1a6d2f7db5dcbf0756d91b8e Mon Sep 17 00:00:00 2001 From: SirH Date: Thu, 23 Sep 2021 09:49:10 -0400 Subject: [PATCH 36/50] fix: missing properties --- src/structures/AutocompleteInteraction.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/structures/AutocompleteInteraction.js b/src/structures/AutocompleteInteraction.js index 5b0e86a7513a..226d06e77448 100644 --- a/src/structures/AutocompleteInteraction.js +++ b/src/structures/AutocompleteInteraction.js @@ -12,6 +12,24 @@ class AutocompleteInteraction extends Interaction { constructor(client, data) { super(client, data); + /** + * The invoked application command's id + * @type {Snowflake} + */ + this.commandId = data.data.id; + + /** + * The invoked application command's name + * @type {string} + */ + this.commandName = data.data.name; + + /** + * Whether this interaction has already received a response + * @type {boolean} + */ + this.responded = false; + /** * The options passed to the command * @type {CommandInteractionOptionResolver} @@ -57,7 +75,7 @@ class AutocompleteInteraction extends Interaction { * .catch(console.error); */ async respond(options) { - if (this.replied) throw new Error('INTERACTION_ALREADY_REPLIED'); + if (this.responded) throw new Error('INTERACTION_ALREADY_REPLIED'); await this.client.api.interactions(this.id, this.token).callback.post({ data: { @@ -67,7 +85,7 @@ class AutocompleteInteraction extends Interaction { }, }, }); - this.replied = true; + this.responded = true; } } From 8d8dd213d2f05159e9353d65f32766db13c390e2 Mon Sep 17 00:00:00 2001 From: SirH Date: Thu, 23 Sep 2021 10:00:48 -0400 Subject: [PATCH 37/50] fix: necessary properties and types --- src/structures/AutocompleteInteraction.js | 22 ++++++++++++++++++++++ typings/index.d.ts | 6 ++++++ 2 files changed, 28 insertions(+) diff --git a/src/structures/AutocompleteInteraction.js b/src/structures/AutocompleteInteraction.js index 226d06e77448..fc8e5407b80b 100644 --- a/src/structures/AutocompleteInteraction.js +++ b/src/structures/AutocompleteInteraction.js @@ -12,6 +12,19 @@ class AutocompleteInteraction extends Interaction { constructor(client, data) { super(client, data); + /** + * The channel this interaction was sent in + * @type {?TextBasedChannels} + * @name AutocompleteInteraction#channel + * @readonly + */ + + /** + * The id of the channel this interaction was sent in + * @type {Snowflake} + * @name AutocompleteInteraction#channelId + */ + /** * The invoked application command's id * @type {Snowflake} @@ -40,6 +53,15 @@ class AutocompleteInteraction extends Interaction { ); } + /** + * The invoked application command, if it was fetched before + * @type {?ApplicationCommand} + */ + get command() { + const id = this.commandId; + return this.guild?.commands.cache.get(id) ?? this.client.application.commands.cache.get(id) ?? null; + } + /** * Transforms an option received from the API. * @param {APIApplicationCommandOption} option The received option diff --git a/typings/index.d.ts b/typings/index.d.ts index 6ab973e73c00..5e4aff828078 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -583,6 +583,12 @@ export class CommandInteraction extends BaseCommandInteraction { } export class AutocompleteInteraction extends Interaction { + public readonly command: ApplicationCommand | ApplicationCommand<{ guild: GuildResolvable }> | null; + public readonly channel: TextBasedChannels | null; + public channelId: Snowflake; + public commandId: Snowflake; + public commandName: string; + public responded: boolean; public options: CommandInteractionOptionResolver; private transformOption(option: APIApplicationCommandOption): CommandInteractionOption; public respond(options: ApplicationCommandOptionChoice[]): Promise; From 2f11b9fb782a3f58ae8bac5c280203f550bb6ee8 Mon Sep 17 00:00:00 2001 From: SirH Date: Thu, 23 Sep 2021 22:10:43 -0400 Subject: [PATCH 38/50] fix: export autocomplete interaction --- src/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.js b/src/index.js index 09916d9f4f87..d8eb3f4d769d 100644 --- a/src/index.js +++ b/src/index.js @@ -70,6 +70,7 @@ module.exports = { AnonymousGuild: require('./structures/AnonymousGuild'), Application: require('./structures/interfaces/Application'), ApplicationCommand: require('./structures/ApplicationCommand'), + AutocompleteInteraction: require('./structures/AutocompleteInteraction'), Base: require('./structures/Base'), BaseCommandInteraction: require('./structures/BaseCommandInteraction'), BaseGuild: require('./structures/BaseGuild'), From 5af0aa7bba07a3cf166e6ded5595f0f229540a83 Mon Sep 17 00:00:00 2001 From: SirH Date: Sun, 3 Oct 2021 12:09:24 -0400 Subject: [PATCH 39/50] types: return never if non-autocomplete interaction uses focused getter --- typings/index.d.ts | 22 ++++++++++++++++------ typings/tests.ts | 2 +- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index 5e4aff828078..2f8eabe6fd15 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -579,7 +579,7 @@ export abstract class Collector extends EventEmi } export class CommandInteraction extends BaseCommandInteraction { - public options: CommandInteractionOptionResolver; + public options: CommandInteractionOptionResolver; } export class AutocompleteInteraction extends Interaction { @@ -589,12 +589,14 @@ export class AutocompleteInteraction extends Interaction { public commandId: Snowflake; public commandName: string; public responded: boolean; - public options: CommandInteractionOptionResolver; + public options: CommandInteractionOptionResolver; private transformOption(option: APIApplicationCommandOption): CommandInteractionOption; public respond(options: ApplicationCommandOptionChoice[]): Promise; } -export class CommandInteractionOptionResolver { +export class CommandInteractionOptionResolver< + Type extends AutocompleteInteraction | ContextMenuInteraction | CommandInteraction, +> { private constructor(client: Client, options: CommandInteractionOption[], resolved: CommandInteractionResolvedData); public readonly client: Client; public readonly data: readonly CommandInteractionOption[]; @@ -648,12 +650,20 @@ export class CommandInteractionOptionResolver { ): NonNullable | null; public getMessage(name: string, required: true): NonNullable; public getMessage(name: string, required?: boolean): NonNullable | null; - public getFocused(getFull: true): ApplicationCommandOptionChoice; - public getFocused(getFull?: boolean): string | number; + public getFocused< + T extends InteractionOptionResolverReturn, + >(getFull: true): T; + public getFocused>( + getFull?: boolean, + ): T; } +export type InteractionOptionResolverReturn = T extends AllowedInteraction + ? ReturnType + : never; + export class ContextMenuInteraction extends BaseCommandInteraction { - public options: CommandInteractionOptionResolver; + public options: CommandInteractionOptionResolver; public targetId: Snowflake; public targetType: Exclude; private resolveContextMenuOptions(data: APIApplicationCommandInteractionData): CommandInteractionOption[]; diff --git a/typings/tests.ts b/typings/tests.ts index 3d7a5d43526d..d1be5f44b34c 100644 --- a/typings/tests.ts +++ b/typings/tests.ts @@ -858,7 +858,7 @@ if (interaction.inGuild()) assertType(interaction.guildId); client.on('interactionCreate', async interaction => { if (interaction.isCommand()) { assertType(interaction); - assertType(interaction.options); + assertType>(interaction.options); assertType(interaction.options.data); const optionalOption = interaction.options.get('name'); From 3b0ee880f8ed1a36775d053a61e09e5e802f8217 Mon Sep 17 00:00:00 2001 From: SirH Date: Mon, 27 Sep 2021 18:49:41 -0400 Subject: [PATCH 40/50] fix: options equal function to compare with autocomplete --- src/structures/ApplicationCommand.js | 2 ++ typings/index.d.ts | 10 ++++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/structures/ApplicationCommand.js b/src/structures/ApplicationCommand.js index 7260fe63052e..b026d4ceae26 100644 --- a/src/structures/ApplicationCommand.js +++ b/src/structures/ApplicationCommand.js @@ -200,6 +200,7 @@ class ApplicationCommand extends Base { command.name !== this.name || ('description' in command && command.description !== this.description) || ('version' in command && command.version !== this.version) || + ('autocomplete' in command && command.autocomplete !== this.autocomplete) || (commandType && commandType !== this.type) || // Future proof for options being nullable // TODO: remove ?? 0 on each when nullable @@ -255,6 +256,7 @@ class ApplicationCommand extends Base { option.name !== existing.name || optionType !== existing.type || option.description !== existing.description || + option.autocomplete !== existing.autocomplete || (option.required ?? (['SUB_COMMAND', 'SUB_COMMAND_GROUP'].includes(optionType) ? undefined : false)) !== existing.required || option.choices?.length !== existing.choices?.length || diff --git a/typings/index.d.ts b/typings/index.d.ts index 2f8eabe6fd15..4e4e5425daeb 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -650,12 +650,10 @@ export class CommandInteractionOptionResolver< ): NonNullable | null; public getMessage(name: string, required: true): NonNullable; public getMessage(name: string, required?: boolean): NonNullable | null; - public getFocused< - T extends InteractionOptionResolverReturn, - >(getFull: true): T; - public getFocused>( - getFull?: boolean, - ): T; + public getFocused( + getFull: true, + ): InteractionOptionResolverReturn; + public getFocused(getFull?: boolean): InteractionOptionResolverReturn; } export type InteractionOptionResolverReturn = T extends AllowedInteraction From 76d54797679f587face24aeb7d0befac19977d9f Mon Sep 17 00:00:00 2001 From: SirH Date: Sun, 3 Oct 2021 12:51:08 -0400 Subject: [PATCH 41/50] fix: remove redundant channel jsdoc in classes --- src/structures/AutocompleteInteraction.js | 7 ------- src/structures/BaseCommandInteraction.js | 7 ------- 2 files changed, 14 deletions(-) diff --git a/src/structures/AutocompleteInteraction.js b/src/structures/AutocompleteInteraction.js index fc8e5407b80b..4c5d8369677f 100644 --- a/src/structures/AutocompleteInteraction.js +++ b/src/structures/AutocompleteInteraction.js @@ -12,13 +12,6 @@ class AutocompleteInteraction extends Interaction { constructor(client, data) { super(client, data); - /** - * The channel this interaction was sent in - * @type {?TextBasedChannels} - * @name AutocompleteInteraction#channel - * @readonly - */ - /** * The id of the channel this interaction was sent in * @type {Snowflake} diff --git a/src/structures/BaseCommandInteraction.js b/src/structures/BaseCommandInteraction.js index dedf65dcf040..0ddaf6bfee48 100644 --- a/src/structures/BaseCommandInteraction.js +++ b/src/structures/BaseCommandInteraction.js @@ -16,13 +16,6 @@ class BaseCommandInteraction extends Interaction { constructor(client, data) { super(client, data); - /** - * The channel this interaction was sent in - * @type {?TextBasedChannels} - * @name BaseCommandInteraction#channel - * @readonly - */ - /** * The id of the channel this interaction was sent in * @type {Snowflake} From 86e4ea2a78c334245a8c944b4de775f2f8d37efc Mon Sep 17 00:00:00 2001 From: SirH Date: Fri, 15 Oct 2021 16:42:46 -0400 Subject: [PATCH 42/50] types: applied generic variable for all option resolver methods --- typings/index.d.ts | 124 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 101 insertions(+), 23 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index 1fc24093c804..3319dc45a386 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -649,45 +649,123 @@ export class CommandInteractionOptionResolver< public get(name: string, required: true): CommandInteractionOption; public get(name: string, required?: boolean): CommandInteractionOption | null; - public getSubcommand(required?: true): string; - public getSubcommand(required: boolean): string | null; - public getSubcommandGroup(required?: true): string; - public getSubcommandGroup(required: boolean): string | null; - public getBoolean(name: string, required: true): boolean; - public getBoolean(name: string, required?: boolean): boolean | null; - public getChannel(name: string, required: true): NonNullable; - public getChannel(name: string, required?: boolean): NonNullable | null; - public getString(name: string, required: true): string; - public getString(name: string, required?: boolean): string | null; - public getInteger(name: string, required: true): number; - public getInteger(name: string, required?: boolean): number | null; - public getNumber(name: string, required: true): number; - public getNumber(name: string, required?: boolean): number | null; + public getSubcommand( + required?: true, + ): InteractionOptionResolverReturn; + public getSubcommand( + required: boolean, + ): InteractionOptionResolverReturn; + public getSubcommandGroup( + required?: true, + ): InteractionOptionResolverReturn; + public getSubcommandGroup( + required: boolean, + ): InteractionOptionResolverReturn; + public getBoolean( + name: string, + required: true, + ): InteractionOptionResolverReturn; + public getBoolean( + name: string, + required?: boolean, + ): InteractionOptionResolverReturn; + public getChannel( + name: string, + required: true, + ): InteractionOptionResolverReturn< + Type, + CommandInteraction | AutocompleteInteraction, + NonNullable + >; + public getChannel( + name: string, + required?: boolean, + ): InteractionOptionResolverReturn< + Type, + CommandInteraction | AutocompleteInteraction, + NonNullable | null + >; + public getString( + name: string, + required: true, + ): InteractionOptionResolverReturn; + public getString( + name: string, + required?: boolean, + ): InteractionOptionResolverReturn; + public getInteger( + name: string, + required: true, + ): InteractionOptionResolverReturn; + public getInteger( + name: string, + required?: boolean, + ): InteractionOptionResolverReturn; + public getNumber( + name: string, + required: true, + ): InteractionOptionResolverReturn; + public getNumber( + name: string, + required?: boolean, + ): InteractionOptionResolverReturn; public getUser(name: string, required: true): NonNullable; public getUser(name: string, required?: boolean): NonNullable | null; public getMember(name: string, required: true): NonNullable; public getMember(name: string, required?: boolean): NonNullable | null; - public getRole(name: string, required: true): NonNullable; - public getRole(name: string, required?: boolean): NonNullable | null; + public getRole( + name: string, + required: true, + ): InteractionOptionResolverReturn< + Type, + CommandInteraction | AutocompleteInteraction, + NonNullable + >; + public getRole( + name: string, + required?: boolean, + ): InteractionOptionResolverReturn< + Type, + CommandInteraction | AutocompleteInteraction, + NonNullable | null + >; public getMentionable( name: string, required: true, - ): NonNullable; + ): InteractionOptionResolverReturn< + Type, + CommandInteraction | AutocompleteInteraction, + NonNullable + >; public getMentionable( name: string, required?: boolean, - ): NonNullable | null; - public getMessage(name: string, required: true): NonNullable; - public getMessage(name: string, required?: boolean): NonNullable | null; + ): InteractionOptionResolverReturn< + Type, + CommandInteraction | AutocompleteInteraction, + NonNullable | null + >; + public getMessage( + name: string, + required: true, + ): InteractionOptionResolverReturn>; + public getMessage( + name: string, + required?: boolean, + ): InteractionOptionResolverReturn< + Type, + ContextMenuInteraction, + NonNullable | null + >; public getFocused( getFull: true, ): InteractionOptionResolverReturn; public getFocused(getFull?: boolean): InteractionOptionResolverReturn; } -export type InteractionOptionResolverReturn = T extends AllowedInteraction - ? ReturnType - : never; +export type EachUnionToKeyOf = Union extends infer U ? keyof U : never; +export type InteractionOptionResolverReturn = + keyof T extends EachUnionToKeyOf ? ReturnType : never; export class ContextMenuInteraction extends BaseCommandInteraction { public options: CommandInteractionOptionResolver; From bcdc01dcc7eed315076aad1c0b80da506a5556f5 Mon Sep 17 00:00:00 2001 From: SirH Date: Wed, 27 Oct 2021 19:42:34 -0400 Subject: [PATCH 43/50] types: apply CacheType generics to AutocompleteInteraction --- typings/index.d.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index f090ed8cb79b..8a0bac2f0c81 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -602,9 +602,8 @@ export class CommandInteraction extends Ba public toString(): string; } -export class AutocompleteInteraction extends Interaction { +export class AutocompleteInteraction extends Interaction { public readonly command: ApplicationCommand | ApplicationCommand<{ guild: GuildResolvable }> | null; - public readonly channel: TextBasedChannels | null; public channelId: Snowflake; public commandId: Snowflake; public commandName: string; From 0cec4d824996a7e2f6898949b920b748205d486f Mon Sep 17 00:00:00 2001 From: SirH Date: Wed, 27 Oct 2021 23:00:09 -0400 Subject: [PATCH 44/50] types: omit option resolver methods from interactions that don't need it --- typings/index.d.ts | 174 +++++++++++---------------------------------- 1 file changed, 42 insertions(+), 132 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index 8a0bac2f0c81..a28a4e2ed44c 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -276,14 +276,7 @@ export type GuildCacheMessage = CacheTypeReducer< Message | APIMessage >; -export abstract class BaseCommandInteraction< - Cached extends CacheType = CacheType, - Type extends CommandInteraction | AutocompleteInteraction | ContextMenuInteraction = - | CommandInteraction - | AutocompleteInteraction - | ContextMenuInteraction, -> extends Interaction { - public options: CommandInteractionOptionResolver; +export abstract class BaseCommandInteraction extends Interaction { public readonly command: ApplicationCommand | ApplicationCommand<{ guild: GuildResolvable }> | null; public channelId: Snowflake; public commandId: Snowflake; @@ -595,10 +588,8 @@ export abstract class Collector extends EventEmi public once(event: 'end', listener: (collected: Collection, reason: string) => Awaitable): this; } -export class CommandInteraction extends BaseCommandInteraction< - Cached, - CommandInteraction -> { +export class CommandInteraction extends BaseCommandInteraction { + public options: Omit, 'getMessage' | 'getFocused'>; public toString(): string; } @@ -608,15 +599,12 @@ export class AutocompleteInteraction exten public commandId: Snowflake; public commandName: string; public responded: boolean; - public options: CommandInteractionOptionResolver; + public options: Omit, 'getMessage'>; private transformOption(option: APIApplicationCommandOption): CommandInteractionOption; public respond(options: ApplicationCommandOptionChoice[]): Promise; } -export class CommandInteractionOptionResolver< - Type extends AutocompleteInteraction | ContextMenuInteraction | CommandInteraction, - Cached extends CacheType = CacheType, -> { +export class CommandInteractionOptionResolver { private constructor(client: Client, options: CommandInteractionOption[], resolved: CommandInteractionResolvedData); public readonly client: Client; public readonly data: readonly CommandInteractionOption[]; @@ -640,132 +628,54 @@ export class CommandInteractionOptionResolver< public get(name: string, required: true): CommandInteractionOption; public get(name: string, required?: boolean): CommandInteractionOption | null; - public getSubcommand( - required?: true, - ): InteractionOptionResolverReturn; - public getSubcommand( - required: boolean, - ): InteractionOptionResolverReturn; - public getSubcommandGroup( - required?: true, - ): InteractionOptionResolverReturn; - public getSubcommandGroup( - required: boolean, - ): InteractionOptionResolverReturn; - public getBoolean( - name: string, - required: true, - ): InteractionOptionResolverReturn; - public getBoolean( - name: string, - required?: boolean, - ): InteractionOptionResolverReturn; - public getChannel( - name: string, - required: true, - ): InteractionOptionResolverReturn< - Type, - CommandInteraction | AutocompleteInteraction, - NonNullable['channel']> - >; - public getChannel( - name: string, - required?: boolean, - ): InteractionOptionResolverReturn< - Type, - CommandInteraction | AutocompleteInteraction, - NonNullable['channel']> | null - >; - public getString( - name: string, - required: true, - ): InteractionOptionResolverReturn; - public getString( - name: string, - required?: boolean, - ): InteractionOptionResolverReturn; - public getInteger( - name: string, - required: true, - ): InteractionOptionResolverReturn; - public getInteger( - name: string, - required?: boolean, - ): InteractionOptionResolverReturn; - public getNumber( - name: string, - required: true, - ): InteractionOptionResolverReturn; - public getNumber( - name: string, - required?: boolean, - ): InteractionOptionResolverReturn; + public getSubcommand(required?: true): string; + public getSubcommand(required: boolean): string | null; + public getSubcommandGroup(required?: true): string; + public getSubcommandGroup(required: boolean): string | null; + public getBoolean(name: string, required: true): boolean; + public getBoolean(name: string, required?: boolean): boolean | null; + public getChannel(name: string, required: true): NonNullable['channel']>; + public getChannel(name: string, required?: boolean): NonNullable['channel']> | null; + public getString(name: string, required: true): string; + public getString(name: string, required?: boolean): string | null; + public getInteger(name: string, required: true): number; + public getInteger(name: string, required?: boolean): number | null; + public getNumber(name: string, required: true): number; + public getNumber(name: string, required?: boolean): number | null; public getUser(name: string, required: true): NonNullable['user']>; public getUser(name: string, required?: boolean): NonNullable['user']> | null; public getMember(name: string, required: true): NonNullable['member']>; public getMember(name: string, required?: boolean): NonNullable['member']> | null; - public getRole( - name: string, - required: true, - ): InteractionOptionResolverReturn< - Type, - CommandInteraction | AutocompleteInteraction, - NonNullable['role']> - >; - public getRole( - name: string, - required?: boolean, - ): InteractionOptionResolverReturn< - Type, - CommandInteraction | AutocompleteInteraction, - NonNullable['role']> | null - >; + public getRole(name: string, required: true): NonNullable['role']>; + public getRole(name: string, required?: boolean): NonNullable['role']> | null; public getMentionable( name: string, required: true, - ): InteractionOptionResolverReturn< - Type, - CommandInteraction | AutocompleteInteraction, - NonNullable['member' | 'role' | 'user']> - >; + ): NonNullable['member' | 'role' | 'user']>; public getMentionable( name: string, required?: boolean, - ): InteractionOptionResolverReturn< - Type, - CommandInteraction | AutocompleteInteraction, - NonNullable['member' | 'role' | 'user']> | null + ): NonNullable['member' | 'role' | 'user']> | null; + public getMessage(name: string, required: true): NonNullable['message']>; + public getMessage(name: string, required?: boolean): NonNullable['message']> | null; + public getFocused(getFull: true): ApplicationCommandOptionChoice; + public getFocused(getFull?: boolean): string | number; +} + +export class ContextMenuInteraction extends BaseCommandInteraction { + public options: Omit< + CommandInteractionOptionResolver, + | 'getFocused' + | 'getMentionable' + | 'getRole' + | 'getNumber' + | 'getInteger' + | 'getString' + | 'getChannel' + | 'getBoolean' + | 'getSubcommandGroup' + | 'getSubcommand' >; - public getMessage( - name: string, - required: true, - ): InteractionOptionResolverReturn< - Type, - ContextMenuInteraction, - NonNullable['message']> - >; - public getMessage( - name: string, - required?: boolean, - ): InteractionOptionResolverReturn< - Type, - ContextMenuInteraction, - NonNullable['message']> | null - >; - public getFocused( - getFull: true, - ): InteractionOptionResolverReturn; - public getFocused(getFull?: boolean): InteractionOptionResolverReturn; -} - -export type EachUnionToKeyOf = Union extends infer U ? keyof U : never; -export type InteractionOptionResolverReturn = - keyof T extends EachUnionToKeyOf ? ReturnType : never; - -export class ContextMenuInteraction extends BaseCommandInteraction< - Cached, - ContextMenuInteraction -> { public targetId: Snowflake; public targetType: Exclude; private resolveContextMenuOptions(data: APIApplicationCommandInteractionData): CommandInteractionOption[]; From 6e059041d6461f5f97240eca8f0a5d2a56e64dd0 Mon Sep 17 00:00:00 2001 From: SirH Date: Thu, 28 Oct 2021 01:52:28 -0400 Subject: [PATCH 45/50] types: unnecessary generic --- typings/tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typings/tests.ts b/typings/tests.ts index d2130650bfc8..a1be4794c543 100644 --- a/typings/tests.ts +++ b/typings/tests.ts @@ -1021,7 +1021,7 @@ client.on('interactionCreate', async interaction => { } assertType(interaction); - assertType>(interaction.options); + assertType(interaction.options); assertType(interaction.options.data); const optionalOption = interaction.options.get('name'); From b9026f2f0bfd0eabdcc5bb40eea54f74e031c9e7 Mon Sep 17 00:00:00 2001 From: Suneet Tipirneni Date: Thu, 28 Oct 2021 12:27:27 -0400 Subject: [PATCH 46/50] chore: rough commit --- typings/index.d.ts | 74 ++- typings/tests.js | 1205 ++++++++++++++++++++++++++++++++++++++++++++ typings/tests.ts | 3 +- 3 files changed, 1267 insertions(+), 15 deletions(-) create mode 100644 typings/tests.js diff --git a/typings/index.d.ts b/typings/index.d.ts index c167c9066765..66a64e07afe7 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -278,6 +278,19 @@ export type GuildCacheMessage = CacheTypeReducer< export abstract class BaseCommandInteraction extends Interaction { public readonly command: ApplicationCommand | ApplicationCommand<{ guild: GuildResolvable }> | null; + public options: Omit< + CommandInteractionOptionResolver, + | 'getFocused' + | 'getMentionable' + | 'getRole' + | 'getNumber' + | 'getInteger' + | 'getString' + | 'getChannel' + | 'getBoolean' + | 'getSubcommandGroup' + | 'getSubcommand' + >; public channelId: Snowflake; public commandId: Snowflake; public commandName: string; @@ -588,8 +601,40 @@ export abstract class Collector extends EventEmi public once(event: 'end', listener: (collected: Collection, reason: string) => Awaitable): this; } +export interface ApplicationCommandInteractionOptionResolver + extends BaseCommandInteractionOptionResolver { + getSubcommand(required?: true): string; + getSubcommand(required: boolean): string | null; + getSubcommandGroup(required?: true): string; + getSubcommandGroup(required: boolean): string | null; + getBoolean(name: string, required: true): boolean; + getBoolean(name: string, required?: boolean): boolean | null; + getChannel(name: string, required: true): NonNullable['channel']>; + getChannel(name: string, required?: boolean): NonNullable['channel']> | null; + getString(name: string, required: true): string; + getString(name: string, required?: boolean): string | null; + getInteger(name: string, required: true): number; + getInteger(name: string, required?: boolean): number | null; + getNumber(name: string, required: true): number; + getNumber(name: string, required?: boolean): number | null; + getUser(name: string, required: true): NonNullable['user']>; + getUser(name: string, required?: boolean): NonNullable['user']> | null; + getMember(name: string, required: true): NonNullable['member']>; + getMember(name: string, required?: boolean): NonNullable['member']> | null; + getRole(name: string, required: true): NonNullable['role']>; + getRole(name: string, required?: boolean): NonNullable['role']> | null; + getMentionable( + name: string, + required: true, + ): NonNullable['member' | 'role' | 'user']>; + getMentionable( + name: string, + required?: boolean, + ): NonNullable['member' | 'role' | 'user']> | null; +} + export class CommandInteraction extends BaseCommandInteraction { - public options: Omit, 'getMessage' | 'getFocused'>; + public options: Omit, 'getFocused'>; public toString(): string; } @@ -604,6 +649,20 @@ export class AutocompleteInteraction exten public respond(options: ApplicationCommandOptionChoice[]): Promise; } +export type BaseCommandInteractionOptionResolver = Omit< + CommandInteractionOptionResolver, + | 'getFocused' + | 'getMentionable' + | 'getRole' + | 'getNumber' + | 'getInteger' + | 'getString' + | 'getChannel' + | 'getBoolean' + | 'getSubcommandGroup' + | 'getSubcommand' +>; + export class CommandInteractionOptionResolver { private constructor(client: Client, options: CommandInteractionOption[], resolved: CommandInteractionResolvedData); public readonly client: Client; @@ -663,19 +722,6 @@ export class CommandInteractionOptionResolver extends BaseCommandInteraction { - public options: Omit< - CommandInteractionOptionResolver, - | 'getFocused' - | 'getMentionable' - | 'getRole' - | 'getNumber' - | 'getInteger' - | 'getString' - | 'getChannel' - | 'getBoolean' - | 'getSubcommandGroup' - | 'getSubcommand' - >; public targetId: Snowflake; public targetType: Exclude; private resolveContextMenuOptions(data: APIApplicationCommandInteractionData): CommandInteractionOption[]; diff --git a/typings/tests.js b/typings/tests.js new file mode 100644 index 000000000000..2a500f7b11cc --- /dev/null +++ b/typings/tests.js @@ -0,0 +1,1205 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +exports.__esModule = true; +var _1 = require("."); +var client = new _1.Client({ + intents: _1.Intents.FLAGS.GUILDS, + makeCache: _1.Options.cacheWithLimits({ + MessageManager: 200, + // @ts-expect-error + Message: 100, + ThreadManager: { + maxSize: 1000, + keepOverLimit: function (x) { return x.id === '123'; }, + sweepInterval: 5000, + sweepFilter: _1.LimitedCollection.filterByLifetime({ + getComparisonTimestamp: function (x) { var _a; return (_a = x.archiveTimestamp) !== null && _a !== void 0 ? _a : 0; }, + excludeFromSweep: function (x) { return !x.archived; } + }) + } + }) +}); +var testGuildId = '222078108977594368'; // DJS +var testUserId = '987654321098765432'; // example id +var globalCommandId = '123456789012345678'; // example id +var guildCommandId = '234567890123456789'; // example id +client.on('ready', function () { return __awaiter(void 0, void 0, void 0, function () { + var _a, _b, globalCommand, guildCommandFromGlobal, guildCommandFromGuild, globalPermissionsManager, guildPermissionsManager, originalPermissions; + var _c, _d, _e, _f, _g, _h, _j, _k, _l; + return __generator(this, function (_m) { + switch (_m.label) { + case 0: + console.log("Client is logged in as " + client.user.tag + " and ready!"); + // Test fetching all global commands and ones from one guild + _a = assertType; + return [4 /*yield*/, client.application.commands.fetch()]; + case 1: + // Test fetching all global commands and ones from one guild + _a.apply(void 0, [_m.sent()]); + _b = assertType; + return [4 /*yield*/, client.application.commands.fetch({ guildId: testGuildId })]; + case 2: + _b.apply(void 0, [_m.sent()]); + return [4 /*yield*/, ((_c = client.application) === null || _c === void 0 ? void 0 : _c.commands.fetch(globalCommandId))]; + case 3: + globalCommand = _m.sent(); + return [4 /*yield*/, ((_d = client.application) === null || _d === void 0 ? void 0 : _d.commands.fetch(guildCommandId, { guildId: testGuildId }))]; + case 4: + guildCommandFromGlobal = _m.sent(); + return [4 /*yield*/, ((_e = client.guilds.cache.get(testGuildId)) === null || _e === void 0 ? void 0 : _e.commands.fetch(guildCommandId))]; + case 5: + guildCommandFromGuild = _m.sent(); + // @ts-expect-error + return [4 /*yield*/, ((_f = client.guilds.cache.get(testGuildId)) === null || _f === void 0 ? void 0 : _f.commands.fetch(guildCommandId, { guildId: testGuildId }))]; + case 6: + // @ts-expect-error + _m.sent(); + globalPermissionsManager = (_g = client.application) === null || _g === void 0 ? void 0 : _g.commands.permissions; + guildPermissionsManager = (_h = client.guilds.cache.get(testGuildId)) === null || _h === void 0 ? void 0 : _h.commands.permissions; + return [4 /*yield*/, ((_j = client.application) === null || _j === void 0 ? void 0 : _j.commands.permissions.fetch({ guild: testGuildId }))]; + case 7: + originalPermissions = _m.sent(); + // Permissions from global manager + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.add({ + command: globalCommandId, + guild: testGuildId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 8: + // Permissions from global manager + _m.sent(); + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.has({ command: globalCommandId, guild: testGuildId, permissionId: testGuildId }))]; + case 9: + _m.sent(); + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.fetch({ guild: testGuildId }))]; + case 10: + _m.sent(); + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.fetch({ command: globalCommandId, guild: testGuildId }))]; + case 11: + _m.sent(); + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.remove({ command: globalCommandId, guild: testGuildId, roles: [testGuildId] }))]; + case 12: + _m.sent(); + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.remove({ command: globalCommandId, guild: testGuildId, users: [testUserId] }))]; + case 13: + _m.sent(); + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.remove({ + command: globalCommandId, + guild: testGuildId, + roles: [testGuildId], + users: [testUserId] + }))]; + case 14: + _m.sent(); + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.set({ + command: globalCommandId, + guild: testGuildId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 15: + _m.sent(); + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.set({ + guild: testGuildId, + fullPermissions: [{ id: globalCommandId, permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }] + }))]; + case 16: + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.add({ + command: globalCommandId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 17: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.has({ command: globalCommandId, permissionId: testGuildId }))]; + case 18: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.fetch())]; + case 19: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.fetch({ command: globalCommandId }))]; + case 20: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.remove({ command: globalCommandId, roles: [testGuildId] }))]; + case 21: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.remove({ command: globalCommandId, users: [testUserId] }))]; + case 22: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.remove({ command: globalCommandId, roles: [testGuildId], users: [testUserId] }))]; + case 23: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.set({ + command: globalCommandId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 24: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.set({ + fullPermissions: [{ id: globalCommandId, permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }] + }))]; + case 25: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.set({ + command: globalCommandId, + guild: testGuildId, + fullPermissions: [{ id: globalCommandId, permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }] + }))]; + case 26: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.add({ + guild: testGuildId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 27: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.has({ guild: testGuildId, permissionId: testGuildId }))]; + case 28: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.remove({ guild: testGuildId, roles: [testGuildId] }))]; + case 29: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.remove({ guild: testGuildId, users: [testUserId] }))]; + case 30: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.remove({ guild: testGuildId, roles: [testGuildId], users: [testUserId] }))]; + case 31: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.set({ + guild: testGuildId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 32: + // @ts-expect-error + _m.sent(); + // Permissions from guild manager + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.add({ + command: globalCommandId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 33: + // Permissions from guild manager + _m.sent(); + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.has({ command: globalCommandId, permissionId: testGuildId }))]; + case 34: + _m.sent(); + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.fetch({}))]; + case 35: + _m.sent(); + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.fetch({ command: globalCommandId }))]; + case 36: + _m.sent(); + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.remove({ command: globalCommandId, roles: [testGuildId] }))]; + case 37: + _m.sent(); + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.remove({ command: globalCommandId, users: [testUserId] }))]; + case 38: + _m.sent(); + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.remove({ command: globalCommandId, roles: [testGuildId], users: [testUserId] }))]; + case 39: + _m.sent(); + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.set({ + command: globalCommandId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 40: + _m.sent(); + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.set({ + fullPermissions: [{ id: globalCommandId, permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }] + }))]; + case 41: + _m.sent(); + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.add({ + command: globalCommandId, + // @ts-expect-error + guild: testGuildId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 42: + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.has({ command: globalCommandId, guild: testGuildId, permissionId: testGuildId }))]; + case 43: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.fetch({ guild: testGuildId }))]; + case 44: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.fetch({ command: globalCommandId, guild: testGuildId }))]; + case 45: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.remove({ command: globalCommandId, guild: testGuildId, roles: [testGuildId] }))]; + case 46: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.remove({ command: globalCommandId, guild: testGuildId, users: [testUserId] }))]; + case 47: + // @ts-expect-error + _m.sent(); + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.remove({ + command: globalCommandId, + // @ts-expect-error + guild: testGuildId, + roles: [testGuildId], + users: [testUserId] + }))]; + case 48: + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.set({ + command: globalCommandId, + guild: testGuildId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 49: + // @ts-expect-error + _m.sent(); + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.set({ + // @ts-expect-error + guild: testGuildId, + fullPermissions: [{ id: globalCommandId, permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }] + }))]; + case 50: + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.add({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }))]; + case 51: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.has({ permissionId: testGuildId }))]; + case 52: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.remove({ roles: [testGuildId] }))]; + case 53: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.remove({ users: [testUserId] }))]; + case 54: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.remove({ roles: [testGuildId], users: [testUserId] }))]; + case 55: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.set({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }))]; + case 56: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.set({ + command: globalCommandId, + fullPermissions: [{ id: globalCommandId, permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }] + }))]; + case 57: + // @ts-expect-error + _m.sent(); + // Permissions from cached global ApplicationCommand + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.add({ + guild: testGuildId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 58: + // Permissions from cached global ApplicationCommand + _m.sent(); + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.has({ guild: testGuildId, permissionId: testGuildId }))]; + case 59: + _m.sent(); + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.fetch({ guild: testGuildId }))]; + case 60: + _m.sent(); + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.remove({ guild: testGuildId, roles: [testGuildId] }))]; + case 61: + _m.sent(); + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.remove({ guild: testGuildId, users: [testUserId] }))]; + case 62: + _m.sent(); + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.remove({ guild: testGuildId, roles: [testGuildId], users: [testUserId] }))]; + case 63: + _m.sent(); + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.set({ + guild: testGuildId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 64: + _m.sent(); + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.add({ + // @ts-expect-error + command: globalCommandId, + guild: testGuildId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 65: + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.has({ command: globalCommandId, guild: testGuildId, permissionId: testGuildId }))]; + case 66: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.fetch({ command: globalCommandId, guild: testGuildId }))]; + case 67: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.remove({ command: globalCommandId, guild: testGuildId, roles: [testGuildId] }))]; + case 68: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.remove({ command: globalCommandId, guild: testGuildId, users: [testUserId] }))]; + case 69: + // @ts-expect-error + _m.sent(); + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.remove({ + // @ts-expect-error + command: globalCommandId, + guild: testGuildId, + roles: [testGuildId], + users: [testUserId] + }))]; + case 70: + _m.sent(); + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.set({ + // @ts-expect-error + command: globalCommandId, + guild: testGuildId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 71: + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.add({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }))]; + case 72: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.has({ permissionId: testGuildId }))]; + case 73: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.fetch({}))]; + case 74: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.remove({ roles: [testGuildId] }))]; + case 75: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.remove({ users: [testUserId] }))]; + case 76: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.remove({ roles: [testGuildId], users: [testUserId] }))]; + case 77: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.set({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }))]; + case 78: + // @ts-expect-error + _m.sent(); + // Permissions from cached guild ApplicationCommand + return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.add({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }))]; + case 79: + // Permissions from cached guild ApplicationCommand + _m.sent(); + return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.has({ permissionId: testGuildId }))]; + case 80: + _m.sent(); + return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.fetch({}))]; + case 81: + _m.sent(); + return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.remove({ roles: [testGuildId] }))]; + case 82: + _m.sent(); + return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.remove({ users: [testUserId] }))]; + case 83: + _m.sent(); + return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.remove({ roles: [testGuildId], users: [testUserId] }))]; + case 84: + _m.sent(); + return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.set({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }))]; + case 85: + _m.sent(); + return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.add({ + // @ts-expect-error + command: globalCommandId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 86: + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.has({ command: guildCommandId, permissionId: testGuildId }))]; + case 87: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.remove({ command: guildCommandId, roles: [testGuildId] }))]; + case 88: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.remove({ command: guildCommandId, users: [testUserId] }))]; + case 89: + // @ts-expect-error + _m.sent(); + return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.remove({ + // @ts-expect-error + command: guildCommandId, + roles: [testGuildId], + users: [testUserId] + }))]; + case 90: + _m.sent(); + return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.set({ + // @ts-expect-error + command: guildCommandId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 91: + _m.sent(); + return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.add({ + // @ts-expect-error + guild: testGuildId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 92: + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.has({ guild: testGuildId, permissionId: testGuildId }))]; + case 93: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.remove({ guild: testGuildId, roles: [testGuildId] }))]; + case 94: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.remove({ guild: testGuildId, users: [testUserId] }))]; + case 95: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.remove({ guild: testGuildId, roles: [testGuildId], users: [testUserId] }))]; + case 96: + // @ts-expect-error + _m.sent(); + return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.set({ + // @ts-expect-error + guild: testGuildId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 97: + _m.sent(); + return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.add({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }))]; + case 98: + _m.sent(); + return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.has({ permissionId: testGuildId }))]; + case 99: + _m.sent(); + return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.fetch({}))]; + case 100: + _m.sent(); + return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.remove({ roles: [testGuildId] }))]; + case 101: + _m.sent(); + return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.remove({ users: [testUserId] }))]; + case 102: + _m.sent(); + return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.remove({ roles: [testGuildId], users: [testUserId] }))]; + case 103: + _m.sent(); + return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.set({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }))]; + case 104: + _m.sent(); + return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.add({ + // @ts-expect-error + command: globalCommandId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 105: + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.has({ command: guildCommandId, permissionId: testGuildId }))]; + case 106: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.remove({ command: guildCommandId, roles: [testGuildId] }))]; + case 107: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.remove({ command: guildCommandId, users: [testUserId] }))]; + case 108: + // @ts-expect-error + _m.sent(); + return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.remove({ + // @ts-expect-error + command: guildCommandId, + roles: [testGuildId], + users: [testUserId] + }))]; + case 109: + _m.sent(); + return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.set({ + // @ts-expect-error + command: guildCommandId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 110: + _m.sent(); + return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.add({ + // @ts-expect-error + guild: testGuildId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 111: + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.has({ guild: testGuildId, permissionId: testGuildId }))]; + case 112: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.remove({ guild: testGuildId, roles: [testGuildId] }))]; + case 113: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.remove({ guild: testGuildId, users: [testUserId] }))]; + case 114: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.remove({ guild: testGuildId, roles: [testGuildId], users: [testUserId] }))]; + case 115: + // @ts-expect-error + _m.sent(); + return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.set({ + // @ts-expect-error + guild: testGuildId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 116: + _m.sent(); + (_k = client.application) === null || _k === void 0 ? void 0 : _k.commands.permissions.set({ + guild: testGuildId, + fullPermissions: (_l = originalPermissions === null || originalPermissions === void 0 ? void 0 : originalPermissions.map(function (permissions, id) { return ({ permissions: permissions, id: id }); })) !== null && _l !== void 0 ? _l : [] + }); + return [2 /*return*/]; + } + }); +}); }); +client.on('guildCreate', function (g) { + var channel = g.channels.cache.random(); + if (!channel) + return; + channel.setName('foo').then(function (updatedChannel) { + console.log("New channel name: " + updatedChannel.name); + }); + // @ts-expect-error no options + assertIsPromiseMember(g.members.add(testUserId)); + // @ts-expect-error no access token + assertIsPromiseMember(g.members.add(testUserId, {})); + // @ts-expect-error invalid role resolvable + assertIsPromiseMember(g.members.add(testUserId, { accessToken: 'totallyRealAccessToken', roles: [g.roles.cache] })); + assertType(g.members.add(testUserId, { accessToken: 'totallyRealAccessToken', fetchWhenExisting: false })); + assertIsPromiseMember(g.members.add(testUserId, { accessToken: 'totallyRealAccessToken' })); + assertIsPromiseMember(g.members.add(testUserId, { + accessToken: 'totallyRealAccessToken', + mute: true, + deaf: false, + roles: [g.roles.cache.first()], + force: true, + fetchWhenExisting: true + })); +}); +client.on('messageReactionRemoveAll', function (message) { return __awaiter(void 0, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + console.log("messageReactionRemoveAll - id: " + message.id + " (" + message.id.length + ")"); + if (!message.partial) return [3 /*break*/, 2]; + return [4 /*yield*/, message.fetch()]; + case 1: + message = _a.sent(); + _a.label = 2; + case 2: + console.log("messageReactionRemoveAll - content: " + message.content); + return [2 /*return*/]; + } + }); +}); }); +client.on('messageCreate', function (message) { return __awaiter(void 0, void 0, void 0, function () { + var channel, attachment, embed, component, _a, buttonCollector_1, buttonCollector, selectMenuCollector, defaultCollector, semiDefaultCollector, semiDefaultCollectorChannel, interactionOptions, webhook; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + channel = message.channel; + assertIsMessage(channel.send('string')); + assertIsMessage(channel.send({})); + assertIsMessage(channel.send({ embeds: [] })); + attachment = new _1.MessageAttachment('file.png'); + embed = new _1.MessageEmbed(); + assertIsMessage(channel.send({ files: [attachment] })); + assertIsMessage(channel.send({ embeds: [embed] })); + assertIsMessage(channel.send({ embeds: [embed], files: [attachment] })); + if (!message.inGuild()) return [3 /*break*/, 3]; + assertType(message); + return [4 /*yield*/, message.awaitMessageComponent({ componentType: 'BUTTON' })]; + case 1: + component = _b.sent(); + assertType(component); + _a = assertType; + return [4 /*yield*/, component.reply({ fetchReply: true })]; + case 2: + _a.apply(void 0, [_b.sent()]); + buttonCollector_1 = message.createMessageComponentCollector({ componentType: 'BUTTON' }); + assertType(buttonCollector_1); + assertType(message.channel); + _b.label = 3; + case 3: + assertType(message.channel); + // @ts-expect-error + assertType(message.channel); + // @ts-expect-error + channel.send(); + // @ts-expect-error + channel.send({ another: 'property' }); + buttonCollector = message.createMessageComponentCollector({ componentType: 'BUTTON' }); + assertType(message.awaitMessageComponent({ componentType: 'BUTTON' })); + assertType(channel.awaitMessageComponent({ componentType: 'BUTTON' })); + assertType(buttonCollector); + selectMenuCollector = message.createMessageComponentCollector({ componentType: 'SELECT_MENU' }); + assertType(message.awaitMessageComponent({ componentType: 'SELECT_MENU' })); + assertType(channel.awaitMessageComponent({ componentType: 'SELECT_MENU' })); + assertType(selectMenuCollector); + defaultCollector = message.createMessageComponentCollector(); + assertType(message.awaitMessageComponent()); + assertType(channel.awaitMessageComponent()); + assertType(defaultCollector); + semiDefaultCollector = message.createMessageComponentCollector({ time: 10000 }); + assertType(semiDefaultCollector); + semiDefaultCollectorChannel = message.createMessageComponentCollector({ time: 10000 }); + assertType(semiDefaultCollectorChannel); + interactionOptions = message.createMessageComponentCollector({ interactionType: 'APPLICATION_COMMAND' }); + // Make sure filter parameters are properly inferred. + message.createMessageComponentCollector({ + filter: function (i) { + assertType(i); + return true; + } + }); + message.createMessageComponentCollector({ + componentType: 'BUTTON', + filter: function (i) { + assertType(i); + return true; + } + }); + message.createMessageComponentCollector({ + componentType: 'SELECT_MENU', + filter: function (i) { + assertType(i); + return true; + } + }); + message.awaitMessageComponent({ + filter: function (i) { + assertType(i); + return true; + } + }); + message.awaitMessageComponent({ + componentType: 'BUTTON', + filter: function (i) { + assertType(i); + return true; + } + }); + message.awaitMessageComponent({ + componentType: 'SELECT_MENU', + filter: function (i) { + assertType(i); + return true; + } + }); + return [4 /*yield*/, message.fetchWebhook()]; + case 4: + webhook = _b.sent(); + if (webhook.isChannelFollower()) { + assertType(webhook.sourceGuild); + assertType(webhook.sourceChannel); + } + else if (webhook.isIncoming()) { + assertType(webhook.token); + } + // @ts-expect-error + assertType(webhook.sourceGuild); + // @ts-expect-error + assertType(webhook.sourceChannel); + // @ts-expect-error + assertType(webhook.token); + channel.awaitMessageComponent({ + filter: function (i) { + assertType(i); + return true; + } + }); + channel.awaitMessageComponent({ + componentType: 'BUTTON', + filter: function (i) { + assertType(i); + return true; + } + }); + channel.awaitMessageComponent({ + componentType: 'SELECT_MENU', + filter: function (i) { + assertType(i); + return true; + } + }); + return [2 /*return*/]; + } + }); +}); }); +client.on('interaction', function (interaction) { return __awaiter(void 0, void 0, void 0, function () { + var button, actionRow; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + assertType(interaction.guildId); + assertType(interaction.channelId); + assertType(interaction.member); + if (!interaction.isCommand()) + return [2 /*return*/]; + void new _1.MessageActionRow(); + button = new _1.MessageButton(); + actionRow = new _1.MessageActionRow({ components: [button] }); + return [4 /*yield*/, interaction.reply({ content: 'Hi!', components: [actionRow] })]; + case 1: + _a.sent(); + // @ts-expect-error + return [4 /*yield*/, interaction.reply({ content: 'Hi!', components: [[button]] })]; + case 2: + // @ts-expect-error + _a.sent(); + // @ts-expect-error + void new _1.MessageActionRow({}); + // @ts-expect-error + return [4 /*yield*/, interaction.reply({ content: 'Hi!', components: [button] })]; + case 3: + // @ts-expect-error + _a.sent(); + if (interaction.isMessageComponent()) { + assertType(interaction.channelId); + } + return [2 /*return*/]; + } + }); +}); }); +client.login('absolutely-valid-token'); +// Test client conditional types +client.on('ready', function (client) { + assertType(client); +}); +assertType(loggedInClient.application); +assertType(loggedInClient.readyAt); +assertType(loggedInClient.readyTimestamp); +assertType(loggedInClient.token); +assertType(loggedInClient.uptime); +assertType(loggedInClient.user); +assertType(loggedOutClient.application); +assertType(loggedOutClient.readyAt); +assertType(loggedOutClient.readyTimestamp); +assertType(loggedOutClient.token); +assertType(loggedOutClient.uptime); +assertType(loggedOutClient.user); +assertType(serialize(undefined)); +assertType(serialize(null)); +assertType(serialize([1, 2, 3])); +assertType(serialize(new Set([1, 2, 3]))); +assertType(serialize(new Map([ + [1, '2'], + [2, '4'], +]))); +assertType(serialize(new _1.Permissions(_1.Permissions.FLAGS.ATTACH_FILES))); +assertType(serialize(new _1.Intents(_1.Intents.FLAGS.GUILDS))); +assertType(serialize(new _1.Collection([ + [1, '2'], + [2, '4'], +]))); +assertType(serialize(Symbol('a'))); +assertType(serialize(function () { })); +assertType(serialize(BigInt(42))); +assertType(shardingManager.broadcastEval(function () { return 1; })); +assertType(shardClientUtil.broadcastEval(function () { return 1; })); +assertType(shardingManager.broadcastEval(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { + return [2 /*return*/, 1]; +}); }); })); +assertType(shardClientUtil.broadcastEval(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { + return [2 /*return*/, 1]; +}); }); })); +// Test whether the structures implement send +assertType(dmChannel.send); +assertType(threadChannel); +assertType(newsChannel); +assertType(textChannel); +assertType(user); +assertType(guildMember); +assertType(dmChannel.lastMessage); +assertType(threadChannel.lastMessage); +assertType(newsChannel.lastMessage); +assertType(textChannel.lastMessage); +notPropertyOf(user, 'lastMessage'); +notPropertyOf(user, 'lastMessageId'); +notPropertyOf(guildMember, 'lastMessage'); +notPropertyOf(guildMember, 'lastMessageId'); +messageCollector.on('collect', function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + assertType(args); +}); +reactionCollector.on('dispose', function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + assertType(args); +}); +// Make sure the properties are typed correctly, and that no backwards properties +// (K -> V and V -> K) exist: +assertType(_1.Constants.Events.MESSAGE_CREATE); +assertType(_1.Constants.ShardEvents.CLOSE); +assertType(_1.Constants.Status.CONNECTING); +assertType(_1.Constants.Opcodes.DISPATCH); +assertType(_1.Constants.ClientApplicationAssetTypes.BIG); +{ + assertType(applicationCommandManager.create(applicationCommandData)); + assertType(applicationCommandManager.create(applicationCommandData, '0')); + assertType(applicationCommandManager.edit(applicationCommandResolvable, applicationCommandData)); + assertType(applicationCommandManager.edit(applicationCommandResolvable, applicationCommandData, '0')); + assertType(applicationCommandManager.set([applicationCommandData])); + assertType(applicationCommandManager.set([applicationCommandData], '0')); +} +{ + // Options aren't allowed on this command type. + // @ts-expect-error + applicationNonChoiceOptionData.choices; +} +{ + // Choices should be available. + applicationChoiceOptionData.choices; +} +{ + assertType(applicationSubGroupCommandData.type); + assertType(applicationSubGroupCommandData.options); +} +{ + assertType(applicationSubCommandData.type); + // Check that only subcommands can have no subcommand or subcommand group sub-options. + assertType(applicationSubCommandData.options); +} +assertType(guildApplicationCommandManager.fetch()); +assertType(guildApplicationCommandManager.fetch(undefined, {})); +assertType(guildApplicationCommandManager.fetch('0')); +{ + assertType(guildChannelManager.create('name', { type: 'GUILD_VOICE' })); + assertType(guildChannelManager.create('name', { type: 'GUILD_CATEGORY' })); + assertType(guildChannelManager.create('name', { type: 'GUILD_TEXT' })); + assertType(guildChannelManager.create('name', { type: 'GUILD_NEWS' })); + assertType(guildChannelManager.create('name', { type: 'GUILD_STORE' })); + assertType(guildChannelManager.create('name', { type: 'GUILD_STAGE_VOICE' })); + assertType(guildChannelManager.fetch()); + assertType(guildChannelManager.fetch(undefined, {})); + assertType(guildChannelManager.fetch('0')); +} +assertType(roleManager.fetch()); +assertType(roleManager.fetch(undefined, {})); +assertType(roleManager.fetch('0')); +assertType(guildEmojiManager.fetch()); +assertType(guildEmojiManager.fetch(undefined, {})); +assertType(guildEmojiManager.fetch('0')); +assertType(typing.user); +if (typing.user.partial) + assertType(typing.user.username); +assertType(typing.channel); +if (typing.channel.partial) + assertType(typing.channel.lastMessageId); +assertType(typing.member); +assertType(typing.guild); +if (typing.inGuild()) { + assertType(typing.channel.guild); + assertType(typing.guild); +} +// Test partials structures +client.on('guildMemberRemove', function (member) { + if (member.partial) + return assertType(member.joinedAt); + assertType(member.joinedAt); +}); +client.on('messageReactionAdd', function (reaction) { return __awaiter(void 0, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!reaction.partial) return [3 /*break*/, 2]; + assertType(reaction.count); + return [4 /*yield*/, reaction.fetch()]; + case 1: + reaction = _a.sent(); + _a.label = 2; + case 2: + assertType(reaction.count); + if (reaction.message.partial) + return [2 /*return*/, assertType(reaction.message.content)]; + assertType(reaction.message.content); + return [2 /*return*/]; + } + }); +}); }); +if (interaction.inGuild()) + assertType(interaction.guildId); +client.on('interactionCreate', function (interaction) { return __awaiter(void 0, void 0, void 0, function () { + var msg, btn, optionalOption, requiredOption; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (interaction.inCachedGuild()) { + assertType(interaction.member); + // @ts-expect-error + assertType(interaction); + assertType(interaction); + } + else if (interaction.inRawGuild()) { + assertType(interaction.member); + // @ts-expect-error + consumeCachedInteraction(interaction); + } + else { + assertType(interaction.member); + // @ts-expect-error + consumeCachedInteraction(interaction); + } + if (interaction.isContextMenu()) { + assertType(interaction); + if (interaction.inCachedGuild()) { + assertType(interaction); + assertType(interaction.guild); + assertType(interaction); + } + else if (interaction.inRawGuild()) { + assertType(interaction); + assertType(interaction.guild); + } + else if (interaction.inGuild()) { + assertType(interaction); + assertType(interaction.guild); + } + } + if (interaction.isButton()) { + assertType(interaction); + if (interaction.inCachedGuild()) { + assertType(interaction); + assertType(interaction.guild); + assertType(interaction.reply({ fetchReply: true })); + } + else if (interaction.inRawGuild()) { + assertType(interaction); + assertType(interaction.guild); + assertType(interaction.reply({ fetchReply: true })); + } + else if (interaction.inGuild()) { + assertType(interaction); + assertType(interaction.guild); + assertType(interaction.reply({ fetchReply: true })); + } + } + if (interaction.isMessageComponent()) { + assertType(interaction); + if (interaction.inCachedGuild()) { + assertType(interaction); + assertType(interaction.guild); + assertType(interaction.reply({ fetchReply: true })); + } + else if (interaction.inRawGuild()) { + assertType(interaction); + assertType(interaction.guild); + assertType(interaction.reply({ fetchReply: true })); + } + else if (interaction.inGuild()) { + assertType(interaction); + assertType(interaction.guild); + assertType(interaction.reply({ fetchReply: true })); + } + } + if (interaction.isSelectMenu()) { + assertType(interaction); + if (interaction.inCachedGuild()) { + assertType(interaction); + assertType(interaction.guild); + assertType(interaction.reply({ fetchReply: true })); + } + else if (interaction.inRawGuild()) { + assertType(interaction); + assertType(interaction.guild); + assertType(interaction.reply({ fetchReply: true })); + } + else if (interaction.inGuild()) { + assertType(interaction); + assertType(interaction.guild); + assertType(interaction.reply({ fetchReply: true })); + } + } + if (!interaction.isCommand()) return [3 /*break*/, 6]; + if (!interaction.inRawGuild()) return [3 /*break*/, 1]; + // @ts-expect-error + consumeCachedCommand(interaction); + assertType(interaction); + assertType(interaction.reply({ fetchReply: true })); + assertType(interaction.options.getMember('test')); + assertType(interaction.options.getMember('test', true)); + assertType(interaction.options.getChannel('test', true)); + assertType(interaction.options.getRole('test', true)); + assertType(interaction.options.getMessage('test', true)); + return [3 /*break*/, 5]; + case 1: + if (!interaction.inCachedGuild()) return [3 /*break*/, 4]; + return [4 /*yield*/, interaction.reply({ fetchReply: true })]; + case 2: + msg = _a.sent(); + return [4 /*yield*/, msg.awaitMessageComponent({ componentType: 'BUTTON' })]; + case 3: + btn = _a.sent(); + assertType(msg); + assertType(btn); + assertType(interaction); + assertType(interaction.options.getMember('test', true)); + assertType(interaction.options.getMember('test')); + assertType(interaction); + assertType(interaction.reply({ fetchReply: true })); + assertType(interaction.options.getChannel('test', true)); + assertType(interaction.options.getRole('test', true)); + assertType(interaction.options.getMessage('test', true)); + return [3 /*break*/, 5]; + case 4: + // @ts-expect-error + consumeCachedCommand(interaction); + assertType(interaction); + assertType(interaction.reply({ fetchReply: true })); + assertType(interaction.options.getMember('test')); + assertType(interaction.options.getMember('test', true)); + assertType(interaction.options.getChannel('test', true)); + assertType(interaction.options.getRole('test', true)); + assertType(interaction.options.getMessage('test', true)); + _a.label = 5; + case 5: + assertType(interaction); + assertType(interaction.options); + assertType(interaction.options.data); + optionalOption = interaction.options.get('name'); + requiredOption = interaction.options.get('name', true); + assertType(optionalOption); + assertType(requiredOption); + assertType(requiredOption.options); + assertType(interaction.options.getString('name', booleanValue)); + assertType(interaction.options.getString('name', false)); + assertType(interaction.options.getString('name', true)); + assertType(interaction.options.getSubcommand()); + assertType(interaction.options.getSubcommand(true)); + assertType(interaction.options.getSubcommand(booleanValue)); + assertType(interaction.options.getSubcommand(false)); + assertType(interaction.options.getSubcommandGroup()); + assertType(interaction.options.getSubcommandGroup(true)); + assertType(interaction.options.getSubcommandGroup(booleanValue)); + assertType(interaction.options.getSubcommandGroup(false)); + _a.label = 6; + case 6: return [2 /*return*/]; + } + }); +}); }); diff --git a/typings/tests.ts b/typings/tests.ts index 40de09e1721e..4745b665d3f4 100644 --- a/typings/tests.ts +++ b/typings/tests.ts @@ -19,6 +19,7 @@ import { ApplicationCommandResolvable, ApplicationCommandSubCommandData, ApplicationCommandSubGroupData, + BaseCommandInteraction, ButtonInteraction, CategoryChannel, Client, @@ -921,7 +922,7 @@ client.on('interactionCreate', async interaction => { if (interaction.inCachedGuild()) { assertType(interaction); assertType(interaction.guild); - assertType>(interaction); + assertType>(interaction); } else if (interaction.inRawGuild()) { assertType(interaction); assertType(interaction.guild); From 0080acfd0c69fb70a62335553075acfec6465256 Mon Sep 17 00:00:00 2001 From: Suneet Tipirneni Date: Thu, 28 Oct 2021 15:27:17 -0400 Subject: [PATCH 47/50] fix: type tests --- typings/index.d.ts | 22 +++++++--------------- typings/tests.ts | 6 ++---- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index 66a64e07afe7..4c13d6d66666 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -634,7 +634,10 @@ export interface ApplicationCommandInteractionOptionResolver extends BaseCommandInteraction { - public options: Omit, 'getFocused'>; + public options: Omit, 'getMessage' | 'getFocused'>; + public inGuild(): this is CommandInteraction<'present'> & this; + public inCachedGuild(): this is CommandInteraction<'cached'> & this; + public inRawGuild(): this is CommandInteraction<'raw'> & this; public toString(): string; } @@ -645,24 +648,13 @@ export class AutocompleteInteraction exten public commandName: string; public responded: boolean; public options: Omit, 'getMessage'>; + public inGuild(): this is CommandInteraction<'present'> & this; + public inCachedGuild(): this is CommandInteraction<'cached'> & this; + public inRawGuild(): this is CommandInteraction<'raw'> & this; private transformOption(option: APIApplicationCommandOption): CommandInteractionOption; public respond(options: ApplicationCommandOptionChoice[]): Promise; } -export type BaseCommandInteractionOptionResolver = Omit< - CommandInteractionOptionResolver, - | 'getFocused' - | 'getMentionable' - | 'getRole' - | 'getNumber' - | 'getInteger' - | 'getString' - | 'getChannel' - | 'getBoolean' - | 'getSubcommandGroup' - | 'getSubcommand' ->; - export class CommandInteractionOptionResolver { private constructor(client: Client, options: CommandInteractionOption[], resolved: CommandInteractionResolvedData); public readonly client: Client; diff --git a/typings/tests.ts b/typings/tests.ts index 4745b665d3f4..5cb77954a695 100644 --- a/typings/tests.ts +++ b/typings/tests.ts @@ -21,6 +21,7 @@ import { ApplicationCommandSubGroupData, BaseCommandInteraction, ButtonInteraction, + CacheType, CategoryChannel, Client, ClientApplication, @@ -994,7 +995,6 @@ client.on('interactionCreate', async interaction => { assertType(interaction.options.getChannel('test', true)); assertType(interaction.options.getRole('test', true)); - assertType(interaction.options.getMessage('test', true)); } else if (interaction.inCachedGuild()) { const msg = await interaction.reply({ fetchReply: true }); const btn = await msg.awaitMessageComponent({ componentType: 'BUTTON' }); @@ -1010,7 +1010,6 @@ client.on('interactionCreate', async interaction => { assertType(interaction.options.getChannel('test', true)); assertType(interaction.options.getRole('test', true)); - assertType(interaction.options.getMessage('test', true)); } else { // @ts-expect-error consumeCachedCommand(interaction); @@ -1023,11 +1022,10 @@ client.on('interactionCreate', async interaction => { interaction.options.getChannel('test', true), ); assertType(interaction.options.getRole('test', true)); - assertType(interaction.options.getMessage('test', true)); } assertType(interaction); - assertType(interaction.options); + assertType, 'getFocused' | 'getMessage'>>(interaction.options); assertType(interaction.options.data); const optionalOption = interaction.options.get('name'); From 3b2d7164ce7eec9e2f95030c0950766be994a56e Mon Sep 17 00:00:00 2001 From: Suneet Tipirneni Date: Thu, 28 Oct 2021 15:33:24 -0400 Subject: [PATCH 48/50] Revert "chore: rough commit" This reverts commit b9026f2f0bfd0eabdcc5bb40eea54f74e031c9e7. --- typings/index.d.ts | 58 +-- typings/tests.js | 1205 -------------------------------------------- typings/tests.ts | 3 +- 3 files changed, 14 insertions(+), 1252 deletions(-) delete mode 100644 typings/tests.js diff --git a/typings/index.d.ts b/typings/index.d.ts index 4c13d6d66666..7a2f5f1dc1b2 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -278,19 +278,6 @@ export type GuildCacheMessage = CacheTypeReducer< export abstract class BaseCommandInteraction extends Interaction { public readonly command: ApplicationCommand | ApplicationCommand<{ guild: GuildResolvable }> | null; - public options: Omit< - CommandInteractionOptionResolver, - | 'getFocused' - | 'getMentionable' - | 'getRole' - | 'getNumber' - | 'getInteger' - | 'getString' - | 'getChannel' - | 'getBoolean' - | 'getSubcommandGroup' - | 'getSubcommand' - >; public channelId: Snowflake; public commandId: Snowflake; public commandName: string; @@ -601,38 +588,6 @@ export abstract class Collector extends EventEmi public once(event: 'end', listener: (collected: Collection, reason: string) => Awaitable): this; } -export interface ApplicationCommandInteractionOptionResolver - extends BaseCommandInteractionOptionResolver { - getSubcommand(required?: true): string; - getSubcommand(required: boolean): string | null; - getSubcommandGroup(required?: true): string; - getSubcommandGroup(required: boolean): string | null; - getBoolean(name: string, required: true): boolean; - getBoolean(name: string, required?: boolean): boolean | null; - getChannel(name: string, required: true): NonNullable['channel']>; - getChannel(name: string, required?: boolean): NonNullable['channel']> | null; - getString(name: string, required: true): string; - getString(name: string, required?: boolean): string | null; - getInteger(name: string, required: true): number; - getInteger(name: string, required?: boolean): number | null; - getNumber(name: string, required: true): number; - getNumber(name: string, required?: boolean): number | null; - getUser(name: string, required: true): NonNullable['user']>; - getUser(name: string, required?: boolean): NonNullable['user']> | null; - getMember(name: string, required: true): NonNullable['member']>; - getMember(name: string, required?: boolean): NonNullable['member']> | null; - getRole(name: string, required: true): NonNullable['role']>; - getRole(name: string, required?: boolean): NonNullable['role']> | null; - getMentionable( - name: string, - required: true, - ): NonNullable['member' | 'role' | 'user']>; - getMentionable( - name: string, - required?: boolean, - ): NonNullable['member' | 'role' | 'user']> | null; -} - export class CommandInteraction extends BaseCommandInteraction { public options: Omit, 'getMessage' | 'getFocused'>; public inGuild(): this is CommandInteraction<'present'> & this; @@ -714,6 +669,19 @@ export class CommandInteractionOptionResolver extends BaseCommandInteraction { + public options: Omit< + CommandInteractionOptionResolver, + | 'getFocused' + | 'getMentionable' + | 'getRole' + | 'getNumber' + | 'getInteger' + | 'getString' + | 'getChannel' + | 'getBoolean' + | 'getSubcommandGroup' + | 'getSubcommand' + >; public targetId: Snowflake; public targetType: Exclude; private resolveContextMenuOptions(data: APIApplicationCommandInteractionData): CommandInteractionOption[]; diff --git a/typings/tests.js b/typings/tests.js deleted file mode 100644 index 2a500f7b11cc..000000000000 --- a/typings/tests.js +++ /dev/null @@ -1,1205 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -exports.__esModule = true; -var _1 = require("."); -var client = new _1.Client({ - intents: _1.Intents.FLAGS.GUILDS, - makeCache: _1.Options.cacheWithLimits({ - MessageManager: 200, - // @ts-expect-error - Message: 100, - ThreadManager: { - maxSize: 1000, - keepOverLimit: function (x) { return x.id === '123'; }, - sweepInterval: 5000, - sweepFilter: _1.LimitedCollection.filterByLifetime({ - getComparisonTimestamp: function (x) { var _a; return (_a = x.archiveTimestamp) !== null && _a !== void 0 ? _a : 0; }, - excludeFromSweep: function (x) { return !x.archived; } - }) - } - }) -}); -var testGuildId = '222078108977594368'; // DJS -var testUserId = '987654321098765432'; // example id -var globalCommandId = '123456789012345678'; // example id -var guildCommandId = '234567890123456789'; // example id -client.on('ready', function () { return __awaiter(void 0, void 0, void 0, function () { - var _a, _b, globalCommand, guildCommandFromGlobal, guildCommandFromGuild, globalPermissionsManager, guildPermissionsManager, originalPermissions; - var _c, _d, _e, _f, _g, _h, _j, _k, _l; - return __generator(this, function (_m) { - switch (_m.label) { - case 0: - console.log("Client is logged in as " + client.user.tag + " and ready!"); - // Test fetching all global commands and ones from one guild - _a = assertType; - return [4 /*yield*/, client.application.commands.fetch()]; - case 1: - // Test fetching all global commands and ones from one guild - _a.apply(void 0, [_m.sent()]); - _b = assertType; - return [4 /*yield*/, client.application.commands.fetch({ guildId: testGuildId })]; - case 2: - _b.apply(void 0, [_m.sent()]); - return [4 /*yield*/, ((_c = client.application) === null || _c === void 0 ? void 0 : _c.commands.fetch(globalCommandId))]; - case 3: - globalCommand = _m.sent(); - return [4 /*yield*/, ((_d = client.application) === null || _d === void 0 ? void 0 : _d.commands.fetch(guildCommandId, { guildId: testGuildId }))]; - case 4: - guildCommandFromGlobal = _m.sent(); - return [4 /*yield*/, ((_e = client.guilds.cache.get(testGuildId)) === null || _e === void 0 ? void 0 : _e.commands.fetch(guildCommandId))]; - case 5: - guildCommandFromGuild = _m.sent(); - // @ts-expect-error - return [4 /*yield*/, ((_f = client.guilds.cache.get(testGuildId)) === null || _f === void 0 ? void 0 : _f.commands.fetch(guildCommandId, { guildId: testGuildId }))]; - case 6: - // @ts-expect-error - _m.sent(); - globalPermissionsManager = (_g = client.application) === null || _g === void 0 ? void 0 : _g.commands.permissions; - guildPermissionsManager = (_h = client.guilds.cache.get(testGuildId)) === null || _h === void 0 ? void 0 : _h.commands.permissions; - return [4 /*yield*/, ((_j = client.application) === null || _j === void 0 ? void 0 : _j.commands.permissions.fetch({ guild: testGuildId }))]; - case 7: - originalPermissions = _m.sent(); - // Permissions from global manager - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.add({ - command: globalCommandId, - guild: testGuildId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 8: - // Permissions from global manager - _m.sent(); - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.has({ command: globalCommandId, guild: testGuildId, permissionId: testGuildId }))]; - case 9: - _m.sent(); - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.fetch({ guild: testGuildId }))]; - case 10: - _m.sent(); - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.fetch({ command: globalCommandId, guild: testGuildId }))]; - case 11: - _m.sent(); - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.remove({ command: globalCommandId, guild: testGuildId, roles: [testGuildId] }))]; - case 12: - _m.sent(); - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.remove({ command: globalCommandId, guild: testGuildId, users: [testUserId] }))]; - case 13: - _m.sent(); - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.remove({ - command: globalCommandId, - guild: testGuildId, - roles: [testGuildId], - users: [testUserId] - }))]; - case 14: - _m.sent(); - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.set({ - command: globalCommandId, - guild: testGuildId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 15: - _m.sent(); - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.set({ - guild: testGuildId, - fullPermissions: [{ id: globalCommandId, permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }] - }))]; - case 16: - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.add({ - command: globalCommandId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 17: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.has({ command: globalCommandId, permissionId: testGuildId }))]; - case 18: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.fetch())]; - case 19: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.fetch({ command: globalCommandId }))]; - case 20: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.remove({ command: globalCommandId, roles: [testGuildId] }))]; - case 21: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.remove({ command: globalCommandId, users: [testUserId] }))]; - case 22: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.remove({ command: globalCommandId, roles: [testGuildId], users: [testUserId] }))]; - case 23: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.set({ - command: globalCommandId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 24: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.set({ - fullPermissions: [{ id: globalCommandId, permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }] - }))]; - case 25: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.set({ - command: globalCommandId, - guild: testGuildId, - fullPermissions: [{ id: globalCommandId, permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }] - }))]; - case 26: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.add({ - guild: testGuildId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 27: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.has({ guild: testGuildId, permissionId: testGuildId }))]; - case 28: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.remove({ guild: testGuildId, roles: [testGuildId] }))]; - case 29: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.remove({ guild: testGuildId, users: [testUserId] }))]; - case 30: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.remove({ guild: testGuildId, roles: [testGuildId], users: [testUserId] }))]; - case 31: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.set({ - guild: testGuildId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 32: - // @ts-expect-error - _m.sent(); - // Permissions from guild manager - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.add({ - command: globalCommandId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 33: - // Permissions from guild manager - _m.sent(); - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.has({ command: globalCommandId, permissionId: testGuildId }))]; - case 34: - _m.sent(); - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.fetch({}))]; - case 35: - _m.sent(); - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.fetch({ command: globalCommandId }))]; - case 36: - _m.sent(); - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.remove({ command: globalCommandId, roles: [testGuildId] }))]; - case 37: - _m.sent(); - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.remove({ command: globalCommandId, users: [testUserId] }))]; - case 38: - _m.sent(); - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.remove({ command: globalCommandId, roles: [testGuildId], users: [testUserId] }))]; - case 39: - _m.sent(); - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.set({ - command: globalCommandId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 40: - _m.sent(); - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.set({ - fullPermissions: [{ id: globalCommandId, permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }] - }))]; - case 41: - _m.sent(); - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.add({ - command: globalCommandId, - // @ts-expect-error - guild: testGuildId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 42: - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.has({ command: globalCommandId, guild: testGuildId, permissionId: testGuildId }))]; - case 43: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.fetch({ guild: testGuildId }))]; - case 44: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.fetch({ command: globalCommandId, guild: testGuildId }))]; - case 45: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.remove({ command: globalCommandId, guild: testGuildId, roles: [testGuildId] }))]; - case 46: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.remove({ command: globalCommandId, guild: testGuildId, users: [testUserId] }))]; - case 47: - // @ts-expect-error - _m.sent(); - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.remove({ - command: globalCommandId, - // @ts-expect-error - guild: testGuildId, - roles: [testGuildId], - users: [testUserId] - }))]; - case 48: - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.set({ - command: globalCommandId, - guild: testGuildId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 49: - // @ts-expect-error - _m.sent(); - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.set({ - // @ts-expect-error - guild: testGuildId, - fullPermissions: [{ id: globalCommandId, permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }] - }))]; - case 50: - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.add({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }))]; - case 51: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.has({ permissionId: testGuildId }))]; - case 52: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.remove({ roles: [testGuildId] }))]; - case 53: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.remove({ users: [testUserId] }))]; - case 54: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.remove({ roles: [testGuildId], users: [testUserId] }))]; - case 55: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.set({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }))]; - case 56: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.set({ - command: globalCommandId, - fullPermissions: [{ id: globalCommandId, permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }] - }))]; - case 57: - // @ts-expect-error - _m.sent(); - // Permissions from cached global ApplicationCommand - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.add({ - guild: testGuildId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 58: - // Permissions from cached global ApplicationCommand - _m.sent(); - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.has({ guild: testGuildId, permissionId: testGuildId }))]; - case 59: - _m.sent(); - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.fetch({ guild: testGuildId }))]; - case 60: - _m.sent(); - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.remove({ guild: testGuildId, roles: [testGuildId] }))]; - case 61: - _m.sent(); - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.remove({ guild: testGuildId, users: [testUserId] }))]; - case 62: - _m.sent(); - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.remove({ guild: testGuildId, roles: [testGuildId], users: [testUserId] }))]; - case 63: - _m.sent(); - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.set({ - guild: testGuildId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 64: - _m.sent(); - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.add({ - // @ts-expect-error - command: globalCommandId, - guild: testGuildId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 65: - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.has({ command: globalCommandId, guild: testGuildId, permissionId: testGuildId }))]; - case 66: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.fetch({ command: globalCommandId, guild: testGuildId }))]; - case 67: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.remove({ command: globalCommandId, guild: testGuildId, roles: [testGuildId] }))]; - case 68: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.remove({ command: globalCommandId, guild: testGuildId, users: [testUserId] }))]; - case 69: - // @ts-expect-error - _m.sent(); - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.remove({ - // @ts-expect-error - command: globalCommandId, - guild: testGuildId, - roles: [testGuildId], - users: [testUserId] - }))]; - case 70: - _m.sent(); - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.set({ - // @ts-expect-error - command: globalCommandId, - guild: testGuildId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 71: - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.add({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }))]; - case 72: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.has({ permissionId: testGuildId }))]; - case 73: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.fetch({}))]; - case 74: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.remove({ roles: [testGuildId] }))]; - case 75: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.remove({ users: [testUserId] }))]; - case 76: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.remove({ roles: [testGuildId], users: [testUserId] }))]; - case 77: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.set({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }))]; - case 78: - // @ts-expect-error - _m.sent(); - // Permissions from cached guild ApplicationCommand - return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.add({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }))]; - case 79: - // Permissions from cached guild ApplicationCommand - _m.sent(); - return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.has({ permissionId: testGuildId }))]; - case 80: - _m.sent(); - return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.fetch({}))]; - case 81: - _m.sent(); - return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.remove({ roles: [testGuildId] }))]; - case 82: - _m.sent(); - return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.remove({ users: [testUserId] }))]; - case 83: - _m.sent(); - return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.remove({ roles: [testGuildId], users: [testUserId] }))]; - case 84: - _m.sent(); - return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.set({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }))]; - case 85: - _m.sent(); - return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.add({ - // @ts-expect-error - command: globalCommandId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 86: - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.has({ command: guildCommandId, permissionId: testGuildId }))]; - case 87: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.remove({ command: guildCommandId, roles: [testGuildId] }))]; - case 88: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.remove({ command: guildCommandId, users: [testUserId] }))]; - case 89: - // @ts-expect-error - _m.sent(); - return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.remove({ - // @ts-expect-error - command: guildCommandId, - roles: [testGuildId], - users: [testUserId] - }))]; - case 90: - _m.sent(); - return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.set({ - // @ts-expect-error - command: guildCommandId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 91: - _m.sent(); - return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.add({ - // @ts-expect-error - guild: testGuildId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 92: - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.has({ guild: testGuildId, permissionId: testGuildId }))]; - case 93: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.remove({ guild: testGuildId, roles: [testGuildId] }))]; - case 94: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.remove({ guild: testGuildId, users: [testUserId] }))]; - case 95: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.remove({ guild: testGuildId, roles: [testGuildId], users: [testUserId] }))]; - case 96: - // @ts-expect-error - _m.sent(); - return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.set({ - // @ts-expect-error - guild: testGuildId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 97: - _m.sent(); - return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.add({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }))]; - case 98: - _m.sent(); - return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.has({ permissionId: testGuildId }))]; - case 99: - _m.sent(); - return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.fetch({}))]; - case 100: - _m.sent(); - return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.remove({ roles: [testGuildId] }))]; - case 101: - _m.sent(); - return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.remove({ users: [testUserId] }))]; - case 102: - _m.sent(); - return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.remove({ roles: [testGuildId], users: [testUserId] }))]; - case 103: - _m.sent(); - return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.set({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }))]; - case 104: - _m.sent(); - return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.add({ - // @ts-expect-error - command: globalCommandId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 105: - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.has({ command: guildCommandId, permissionId: testGuildId }))]; - case 106: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.remove({ command: guildCommandId, roles: [testGuildId] }))]; - case 107: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.remove({ command: guildCommandId, users: [testUserId] }))]; - case 108: - // @ts-expect-error - _m.sent(); - return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.remove({ - // @ts-expect-error - command: guildCommandId, - roles: [testGuildId], - users: [testUserId] - }))]; - case 109: - _m.sent(); - return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.set({ - // @ts-expect-error - command: guildCommandId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 110: - _m.sent(); - return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.add({ - // @ts-expect-error - guild: testGuildId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 111: - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.has({ guild: testGuildId, permissionId: testGuildId }))]; - case 112: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.remove({ guild: testGuildId, roles: [testGuildId] }))]; - case 113: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.remove({ guild: testGuildId, users: [testUserId] }))]; - case 114: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.remove({ guild: testGuildId, roles: [testGuildId], users: [testUserId] }))]; - case 115: - // @ts-expect-error - _m.sent(); - return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.set({ - // @ts-expect-error - guild: testGuildId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 116: - _m.sent(); - (_k = client.application) === null || _k === void 0 ? void 0 : _k.commands.permissions.set({ - guild: testGuildId, - fullPermissions: (_l = originalPermissions === null || originalPermissions === void 0 ? void 0 : originalPermissions.map(function (permissions, id) { return ({ permissions: permissions, id: id }); })) !== null && _l !== void 0 ? _l : [] - }); - return [2 /*return*/]; - } - }); -}); }); -client.on('guildCreate', function (g) { - var channel = g.channels.cache.random(); - if (!channel) - return; - channel.setName('foo').then(function (updatedChannel) { - console.log("New channel name: " + updatedChannel.name); - }); - // @ts-expect-error no options - assertIsPromiseMember(g.members.add(testUserId)); - // @ts-expect-error no access token - assertIsPromiseMember(g.members.add(testUserId, {})); - // @ts-expect-error invalid role resolvable - assertIsPromiseMember(g.members.add(testUserId, { accessToken: 'totallyRealAccessToken', roles: [g.roles.cache] })); - assertType(g.members.add(testUserId, { accessToken: 'totallyRealAccessToken', fetchWhenExisting: false })); - assertIsPromiseMember(g.members.add(testUserId, { accessToken: 'totallyRealAccessToken' })); - assertIsPromiseMember(g.members.add(testUserId, { - accessToken: 'totallyRealAccessToken', - mute: true, - deaf: false, - roles: [g.roles.cache.first()], - force: true, - fetchWhenExisting: true - })); -}); -client.on('messageReactionRemoveAll', function (message) { return __awaiter(void 0, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - console.log("messageReactionRemoveAll - id: " + message.id + " (" + message.id.length + ")"); - if (!message.partial) return [3 /*break*/, 2]; - return [4 /*yield*/, message.fetch()]; - case 1: - message = _a.sent(); - _a.label = 2; - case 2: - console.log("messageReactionRemoveAll - content: " + message.content); - return [2 /*return*/]; - } - }); -}); }); -client.on('messageCreate', function (message) { return __awaiter(void 0, void 0, void 0, function () { - var channel, attachment, embed, component, _a, buttonCollector_1, buttonCollector, selectMenuCollector, defaultCollector, semiDefaultCollector, semiDefaultCollectorChannel, interactionOptions, webhook; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - channel = message.channel; - assertIsMessage(channel.send('string')); - assertIsMessage(channel.send({})); - assertIsMessage(channel.send({ embeds: [] })); - attachment = new _1.MessageAttachment('file.png'); - embed = new _1.MessageEmbed(); - assertIsMessage(channel.send({ files: [attachment] })); - assertIsMessage(channel.send({ embeds: [embed] })); - assertIsMessage(channel.send({ embeds: [embed], files: [attachment] })); - if (!message.inGuild()) return [3 /*break*/, 3]; - assertType(message); - return [4 /*yield*/, message.awaitMessageComponent({ componentType: 'BUTTON' })]; - case 1: - component = _b.sent(); - assertType(component); - _a = assertType; - return [4 /*yield*/, component.reply({ fetchReply: true })]; - case 2: - _a.apply(void 0, [_b.sent()]); - buttonCollector_1 = message.createMessageComponentCollector({ componentType: 'BUTTON' }); - assertType(buttonCollector_1); - assertType(message.channel); - _b.label = 3; - case 3: - assertType(message.channel); - // @ts-expect-error - assertType(message.channel); - // @ts-expect-error - channel.send(); - // @ts-expect-error - channel.send({ another: 'property' }); - buttonCollector = message.createMessageComponentCollector({ componentType: 'BUTTON' }); - assertType(message.awaitMessageComponent({ componentType: 'BUTTON' })); - assertType(channel.awaitMessageComponent({ componentType: 'BUTTON' })); - assertType(buttonCollector); - selectMenuCollector = message.createMessageComponentCollector({ componentType: 'SELECT_MENU' }); - assertType(message.awaitMessageComponent({ componentType: 'SELECT_MENU' })); - assertType(channel.awaitMessageComponent({ componentType: 'SELECT_MENU' })); - assertType(selectMenuCollector); - defaultCollector = message.createMessageComponentCollector(); - assertType(message.awaitMessageComponent()); - assertType(channel.awaitMessageComponent()); - assertType(defaultCollector); - semiDefaultCollector = message.createMessageComponentCollector({ time: 10000 }); - assertType(semiDefaultCollector); - semiDefaultCollectorChannel = message.createMessageComponentCollector({ time: 10000 }); - assertType(semiDefaultCollectorChannel); - interactionOptions = message.createMessageComponentCollector({ interactionType: 'APPLICATION_COMMAND' }); - // Make sure filter parameters are properly inferred. - message.createMessageComponentCollector({ - filter: function (i) { - assertType(i); - return true; - } - }); - message.createMessageComponentCollector({ - componentType: 'BUTTON', - filter: function (i) { - assertType(i); - return true; - } - }); - message.createMessageComponentCollector({ - componentType: 'SELECT_MENU', - filter: function (i) { - assertType(i); - return true; - } - }); - message.awaitMessageComponent({ - filter: function (i) { - assertType(i); - return true; - } - }); - message.awaitMessageComponent({ - componentType: 'BUTTON', - filter: function (i) { - assertType(i); - return true; - } - }); - message.awaitMessageComponent({ - componentType: 'SELECT_MENU', - filter: function (i) { - assertType(i); - return true; - } - }); - return [4 /*yield*/, message.fetchWebhook()]; - case 4: - webhook = _b.sent(); - if (webhook.isChannelFollower()) { - assertType(webhook.sourceGuild); - assertType(webhook.sourceChannel); - } - else if (webhook.isIncoming()) { - assertType(webhook.token); - } - // @ts-expect-error - assertType(webhook.sourceGuild); - // @ts-expect-error - assertType(webhook.sourceChannel); - // @ts-expect-error - assertType(webhook.token); - channel.awaitMessageComponent({ - filter: function (i) { - assertType(i); - return true; - } - }); - channel.awaitMessageComponent({ - componentType: 'BUTTON', - filter: function (i) { - assertType(i); - return true; - } - }); - channel.awaitMessageComponent({ - componentType: 'SELECT_MENU', - filter: function (i) { - assertType(i); - return true; - } - }); - return [2 /*return*/]; - } - }); -}); }); -client.on('interaction', function (interaction) { return __awaiter(void 0, void 0, void 0, function () { - var button, actionRow; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - assertType(interaction.guildId); - assertType(interaction.channelId); - assertType(interaction.member); - if (!interaction.isCommand()) - return [2 /*return*/]; - void new _1.MessageActionRow(); - button = new _1.MessageButton(); - actionRow = new _1.MessageActionRow({ components: [button] }); - return [4 /*yield*/, interaction.reply({ content: 'Hi!', components: [actionRow] })]; - case 1: - _a.sent(); - // @ts-expect-error - return [4 /*yield*/, interaction.reply({ content: 'Hi!', components: [[button]] })]; - case 2: - // @ts-expect-error - _a.sent(); - // @ts-expect-error - void new _1.MessageActionRow({}); - // @ts-expect-error - return [4 /*yield*/, interaction.reply({ content: 'Hi!', components: [button] })]; - case 3: - // @ts-expect-error - _a.sent(); - if (interaction.isMessageComponent()) { - assertType(interaction.channelId); - } - return [2 /*return*/]; - } - }); -}); }); -client.login('absolutely-valid-token'); -// Test client conditional types -client.on('ready', function (client) { - assertType(client); -}); -assertType(loggedInClient.application); -assertType(loggedInClient.readyAt); -assertType(loggedInClient.readyTimestamp); -assertType(loggedInClient.token); -assertType(loggedInClient.uptime); -assertType(loggedInClient.user); -assertType(loggedOutClient.application); -assertType(loggedOutClient.readyAt); -assertType(loggedOutClient.readyTimestamp); -assertType(loggedOutClient.token); -assertType(loggedOutClient.uptime); -assertType(loggedOutClient.user); -assertType(serialize(undefined)); -assertType(serialize(null)); -assertType(serialize([1, 2, 3])); -assertType(serialize(new Set([1, 2, 3]))); -assertType(serialize(new Map([ - [1, '2'], - [2, '4'], -]))); -assertType(serialize(new _1.Permissions(_1.Permissions.FLAGS.ATTACH_FILES))); -assertType(serialize(new _1.Intents(_1.Intents.FLAGS.GUILDS))); -assertType(serialize(new _1.Collection([ - [1, '2'], - [2, '4'], -]))); -assertType(serialize(Symbol('a'))); -assertType(serialize(function () { })); -assertType(serialize(BigInt(42))); -assertType(shardingManager.broadcastEval(function () { return 1; })); -assertType(shardClientUtil.broadcastEval(function () { return 1; })); -assertType(shardingManager.broadcastEval(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { - return [2 /*return*/, 1]; -}); }); })); -assertType(shardClientUtil.broadcastEval(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { - return [2 /*return*/, 1]; -}); }); })); -// Test whether the structures implement send -assertType(dmChannel.send); -assertType(threadChannel); -assertType(newsChannel); -assertType(textChannel); -assertType(user); -assertType(guildMember); -assertType(dmChannel.lastMessage); -assertType(threadChannel.lastMessage); -assertType(newsChannel.lastMessage); -assertType(textChannel.lastMessage); -notPropertyOf(user, 'lastMessage'); -notPropertyOf(user, 'lastMessageId'); -notPropertyOf(guildMember, 'lastMessage'); -notPropertyOf(guildMember, 'lastMessageId'); -messageCollector.on('collect', function () { - var args = []; - for (var _i = 0; _i < arguments.length; _i++) { - args[_i] = arguments[_i]; - } - assertType(args); -}); -reactionCollector.on('dispose', function () { - var args = []; - for (var _i = 0; _i < arguments.length; _i++) { - args[_i] = arguments[_i]; - } - assertType(args); -}); -// Make sure the properties are typed correctly, and that no backwards properties -// (K -> V and V -> K) exist: -assertType(_1.Constants.Events.MESSAGE_CREATE); -assertType(_1.Constants.ShardEvents.CLOSE); -assertType(_1.Constants.Status.CONNECTING); -assertType(_1.Constants.Opcodes.DISPATCH); -assertType(_1.Constants.ClientApplicationAssetTypes.BIG); -{ - assertType(applicationCommandManager.create(applicationCommandData)); - assertType(applicationCommandManager.create(applicationCommandData, '0')); - assertType(applicationCommandManager.edit(applicationCommandResolvable, applicationCommandData)); - assertType(applicationCommandManager.edit(applicationCommandResolvable, applicationCommandData, '0')); - assertType(applicationCommandManager.set([applicationCommandData])); - assertType(applicationCommandManager.set([applicationCommandData], '0')); -} -{ - // Options aren't allowed on this command type. - // @ts-expect-error - applicationNonChoiceOptionData.choices; -} -{ - // Choices should be available. - applicationChoiceOptionData.choices; -} -{ - assertType(applicationSubGroupCommandData.type); - assertType(applicationSubGroupCommandData.options); -} -{ - assertType(applicationSubCommandData.type); - // Check that only subcommands can have no subcommand or subcommand group sub-options. - assertType(applicationSubCommandData.options); -} -assertType(guildApplicationCommandManager.fetch()); -assertType(guildApplicationCommandManager.fetch(undefined, {})); -assertType(guildApplicationCommandManager.fetch('0')); -{ - assertType(guildChannelManager.create('name', { type: 'GUILD_VOICE' })); - assertType(guildChannelManager.create('name', { type: 'GUILD_CATEGORY' })); - assertType(guildChannelManager.create('name', { type: 'GUILD_TEXT' })); - assertType(guildChannelManager.create('name', { type: 'GUILD_NEWS' })); - assertType(guildChannelManager.create('name', { type: 'GUILD_STORE' })); - assertType(guildChannelManager.create('name', { type: 'GUILD_STAGE_VOICE' })); - assertType(guildChannelManager.fetch()); - assertType(guildChannelManager.fetch(undefined, {})); - assertType(guildChannelManager.fetch('0')); -} -assertType(roleManager.fetch()); -assertType(roleManager.fetch(undefined, {})); -assertType(roleManager.fetch('0')); -assertType(guildEmojiManager.fetch()); -assertType(guildEmojiManager.fetch(undefined, {})); -assertType(guildEmojiManager.fetch('0')); -assertType(typing.user); -if (typing.user.partial) - assertType(typing.user.username); -assertType(typing.channel); -if (typing.channel.partial) - assertType(typing.channel.lastMessageId); -assertType(typing.member); -assertType(typing.guild); -if (typing.inGuild()) { - assertType(typing.channel.guild); - assertType(typing.guild); -} -// Test partials structures -client.on('guildMemberRemove', function (member) { - if (member.partial) - return assertType(member.joinedAt); - assertType(member.joinedAt); -}); -client.on('messageReactionAdd', function (reaction) { return __awaiter(void 0, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (!reaction.partial) return [3 /*break*/, 2]; - assertType(reaction.count); - return [4 /*yield*/, reaction.fetch()]; - case 1: - reaction = _a.sent(); - _a.label = 2; - case 2: - assertType(reaction.count); - if (reaction.message.partial) - return [2 /*return*/, assertType(reaction.message.content)]; - assertType(reaction.message.content); - return [2 /*return*/]; - } - }); -}); }); -if (interaction.inGuild()) - assertType(interaction.guildId); -client.on('interactionCreate', function (interaction) { return __awaiter(void 0, void 0, void 0, function () { - var msg, btn, optionalOption, requiredOption; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (interaction.inCachedGuild()) { - assertType(interaction.member); - // @ts-expect-error - assertType(interaction); - assertType(interaction); - } - else if (interaction.inRawGuild()) { - assertType(interaction.member); - // @ts-expect-error - consumeCachedInteraction(interaction); - } - else { - assertType(interaction.member); - // @ts-expect-error - consumeCachedInteraction(interaction); - } - if (interaction.isContextMenu()) { - assertType(interaction); - if (interaction.inCachedGuild()) { - assertType(interaction); - assertType(interaction.guild); - assertType(interaction); - } - else if (interaction.inRawGuild()) { - assertType(interaction); - assertType(interaction.guild); - } - else if (interaction.inGuild()) { - assertType(interaction); - assertType(interaction.guild); - } - } - if (interaction.isButton()) { - assertType(interaction); - if (interaction.inCachedGuild()) { - assertType(interaction); - assertType(interaction.guild); - assertType(interaction.reply({ fetchReply: true })); - } - else if (interaction.inRawGuild()) { - assertType(interaction); - assertType(interaction.guild); - assertType(interaction.reply({ fetchReply: true })); - } - else if (interaction.inGuild()) { - assertType(interaction); - assertType(interaction.guild); - assertType(interaction.reply({ fetchReply: true })); - } - } - if (interaction.isMessageComponent()) { - assertType(interaction); - if (interaction.inCachedGuild()) { - assertType(interaction); - assertType(interaction.guild); - assertType(interaction.reply({ fetchReply: true })); - } - else if (interaction.inRawGuild()) { - assertType(interaction); - assertType(interaction.guild); - assertType(interaction.reply({ fetchReply: true })); - } - else if (interaction.inGuild()) { - assertType(interaction); - assertType(interaction.guild); - assertType(interaction.reply({ fetchReply: true })); - } - } - if (interaction.isSelectMenu()) { - assertType(interaction); - if (interaction.inCachedGuild()) { - assertType(interaction); - assertType(interaction.guild); - assertType(interaction.reply({ fetchReply: true })); - } - else if (interaction.inRawGuild()) { - assertType(interaction); - assertType(interaction.guild); - assertType(interaction.reply({ fetchReply: true })); - } - else if (interaction.inGuild()) { - assertType(interaction); - assertType(interaction.guild); - assertType(interaction.reply({ fetchReply: true })); - } - } - if (!interaction.isCommand()) return [3 /*break*/, 6]; - if (!interaction.inRawGuild()) return [3 /*break*/, 1]; - // @ts-expect-error - consumeCachedCommand(interaction); - assertType(interaction); - assertType(interaction.reply({ fetchReply: true })); - assertType(interaction.options.getMember('test')); - assertType(interaction.options.getMember('test', true)); - assertType(interaction.options.getChannel('test', true)); - assertType(interaction.options.getRole('test', true)); - assertType(interaction.options.getMessage('test', true)); - return [3 /*break*/, 5]; - case 1: - if (!interaction.inCachedGuild()) return [3 /*break*/, 4]; - return [4 /*yield*/, interaction.reply({ fetchReply: true })]; - case 2: - msg = _a.sent(); - return [4 /*yield*/, msg.awaitMessageComponent({ componentType: 'BUTTON' })]; - case 3: - btn = _a.sent(); - assertType(msg); - assertType(btn); - assertType(interaction); - assertType(interaction.options.getMember('test', true)); - assertType(interaction.options.getMember('test')); - assertType(interaction); - assertType(interaction.reply({ fetchReply: true })); - assertType(interaction.options.getChannel('test', true)); - assertType(interaction.options.getRole('test', true)); - assertType(interaction.options.getMessage('test', true)); - return [3 /*break*/, 5]; - case 4: - // @ts-expect-error - consumeCachedCommand(interaction); - assertType(interaction); - assertType(interaction.reply({ fetchReply: true })); - assertType(interaction.options.getMember('test')); - assertType(interaction.options.getMember('test', true)); - assertType(interaction.options.getChannel('test', true)); - assertType(interaction.options.getRole('test', true)); - assertType(interaction.options.getMessage('test', true)); - _a.label = 5; - case 5: - assertType(interaction); - assertType(interaction.options); - assertType(interaction.options.data); - optionalOption = interaction.options.get('name'); - requiredOption = interaction.options.get('name', true); - assertType(optionalOption); - assertType(requiredOption); - assertType(requiredOption.options); - assertType(interaction.options.getString('name', booleanValue)); - assertType(interaction.options.getString('name', false)); - assertType(interaction.options.getString('name', true)); - assertType(interaction.options.getSubcommand()); - assertType(interaction.options.getSubcommand(true)); - assertType(interaction.options.getSubcommand(booleanValue)); - assertType(interaction.options.getSubcommand(false)); - assertType(interaction.options.getSubcommandGroup()); - assertType(interaction.options.getSubcommandGroup(true)); - assertType(interaction.options.getSubcommandGroup(booleanValue)); - assertType(interaction.options.getSubcommandGroup(false)); - _a.label = 6; - case 6: return [2 /*return*/]; - } - }); -}); }); diff --git a/typings/tests.ts b/typings/tests.ts index 5cb77954a695..4f5a11c21d3c 100644 --- a/typings/tests.ts +++ b/typings/tests.ts @@ -19,7 +19,6 @@ import { ApplicationCommandResolvable, ApplicationCommandSubCommandData, ApplicationCommandSubGroupData, - BaseCommandInteraction, ButtonInteraction, CacheType, CategoryChannel, @@ -923,7 +922,7 @@ client.on('interactionCreate', async interaction => { if (interaction.inCachedGuild()) { assertType(interaction); assertType(interaction.guild); - assertType>(interaction); + assertType>(interaction); } else if (interaction.inRawGuild()) { assertType(interaction); assertType(interaction.guild); From 28d6ca6804b9018bcfec72e4d305e67c157ac3bf Mon Sep 17 00:00:00 2001 From: Suneet Tipirneni Date: Thu, 28 Oct 2021 15:39:13 -0400 Subject: [PATCH 49/50] Revert "Revert "chore: rough commit"" This reverts commit 3b2d7164ce7eec9e2f95030c0950766be994a56e. --- typings/index.d.ts | 58 ++- typings/tests.js | 1205 ++++++++++++++++++++++++++++++++++++++++++++ typings/tests.ts | 3 +- 3 files changed, 1252 insertions(+), 14 deletions(-) create mode 100644 typings/tests.js diff --git a/typings/index.d.ts b/typings/index.d.ts index 7a2f5f1dc1b2..4c13d6d66666 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -278,6 +278,19 @@ export type GuildCacheMessage = CacheTypeReducer< export abstract class BaseCommandInteraction extends Interaction { public readonly command: ApplicationCommand | ApplicationCommand<{ guild: GuildResolvable }> | null; + public options: Omit< + CommandInteractionOptionResolver, + | 'getFocused' + | 'getMentionable' + | 'getRole' + | 'getNumber' + | 'getInteger' + | 'getString' + | 'getChannel' + | 'getBoolean' + | 'getSubcommandGroup' + | 'getSubcommand' + >; public channelId: Snowflake; public commandId: Snowflake; public commandName: string; @@ -588,6 +601,38 @@ export abstract class Collector extends EventEmi public once(event: 'end', listener: (collected: Collection, reason: string) => Awaitable): this; } +export interface ApplicationCommandInteractionOptionResolver + extends BaseCommandInteractionOptionResolver { + getSubcommand(required?: true): string; + getSubcommand(required: boolean): string | null; + getSubcommandGroup(required?: true): string; + getSubcommandGroup(required: boolean): string | null; + getBoolean(name: string, required: true): boolean; + getBoolean(name: string, required?: boolean): boolean | null; + getChannel(name: string, required: true): NonNullable['channel']>; + getChannel(name: string, required?: boolean): NonNullable['channel']> | null; + getString(name: string, required: true): string; + getString(name: string, required?: boolean): string | null; + getInteger(name: string, required: true): number; + getInteger(name: string, required?: boolean): number | null; + getNumber(name: string, required: true): number; + getNumber(name: string, required?: boolean): number | null; + getUser(name: string, required: true): NonNullable['user']>; + getUser(name: string, required?: boolean): NonNullable['user']> | null; + getMember(name: string, required: true): NonNullable['member']>; + getMember(name: string, required?: boolean): NonNullable['member']> | null; + getRole(name: string, required: true): NonNullable['role']>; + getRole(name: string, required?: boolean): NonNullable['role']> | null; + getMentionable( + name: string, + required: true, + ): NonNullable['member' | 'role' | 'user']>; + getMentionable( + name: string, + required?: boolean, + ): NonNullable['member' | 'role' | 'user']> | null; +} + export class CommandInteraction extends BaseCommandInteraction { public options: Omit, 'getMessage' | 'getFocused'>; public inGuild(): this is CommandInteraction<'present'> & this; @@ -669,19 +714,6 @@ export class CommandInteractionOptionResolver extends BaseCommandInteraction { - public options: Omit< - CommandInteractionOptionResolver, - | 'getFocused' - | 'getMentionable' - | 'getRole' - | 'getNumber' - | 'getInteger' - | 'getString' - | 'getChannel' - | 'getBoolean' - | 'getSubcommandGroup' - | 'getSubcommand' - >; public targetId: Snowflake; public targetType: Exclude; private resolveContextMenuOptions(data: APIApplicationCommandInteractionData): CommandInteractionOption[]; diff --git a/typings/tests.js b/typings/tests.js new file mode 100644 index 000000000000..2a500f7b11cc --- /dev/null +++ b/typings/tests.js @@ -0,0 +1,1205 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +exports.__esModule = true; +var _1 = require("."); +var client = new _1.Client({ + intents: _1.Intents.FLAGS.GUILDS, + makeCache: _1.Options.cacheWithLimits({ + MessageManager: 200, + // @ts-expect-error + Message: 100, + ThreadManager: { + maxSize: 1000, + keepOverLimit: function (x) { return x.id === '123'; }, + sweepInterval: 5000, + sweepFilter: _1.LimitedCollection.filterByLifetime({ + getComparisonTimestamp: function (x) { var _a; return (_a = x.archiveTimestamp) !== null && _a !== void 0 ? _a : 0; }, + excludeFromSweep: function (x) { return !x.archived; } + }) + } + }) +}); +var testGuildId = '222078108977594368'; // DJS +var testUserId = '987654321098765432'; // example id +var globalCommandId = '123456789012345678'; // example id +var guildCommandId = '234567890123456789'; // example id +client.on('ready', function () { return __awaiter(void 0, void 0, void 0, function () { + var _a, _b, globalCommand, guildCommandFromGlobal, guildCommandFromGuild, globalPermissionsManager, guildPermissionsManager, originalPermissions; + var _c, _d, _e, _f, _g, _h, _j, _k, _l; + return __generator(this, function (_m) { + switch (_m.label) { + case 0: + console.log("Client is logged in as " + client.user.tag + " and ready!"); + // Test fetching all global commands and ones from one guild + _a = assertType; + return [4 /*yield*/, client.application.commands.fetch()]; + case 1: + // Test fetching all global commands and ones from one guild + _a.apply(void 0, [_m.sent()]); + _b = assertType; + return [4 /*yield*/, client.application.commands.fetch({ guildId: testGuildId })]; + case 2: + _b.apply(void 0, [_m.sent()]); + return [4 /*yield*/, ((_c = client.application) === null || _c === void 0 ? void 0 : _c.commands.fetch(globalCommandId))]; + case 3: + globalCommand = _m.sent(); + return [4 /*yield*/, ((_d = client.application) === null || _d === void 0 ? void 0 : _d.commands.fetch(guildCommandId, { guildId: testGuildId }))]; + case 4: + guildCommandFromGlobal = _m.sent(); + return [4 /*yield*/, ((_e = client.guilds.cache.get(testGuildId)) === null || _e === void 0 ? void 0 : _e.commands.fetch(guildCommandId))]; + case 5: + guildCommandFromGuild = _m.sent(); + // @ts-expect-error + return [4 /*yield*/, ((_f = client.guilds.cache.get(testGuildId)) === null || _f === void 0 ? void 0 : _f.commands.fetch(guildCommandId, { guildId: testGuildId }))]; + case 6: + // @ts-expect-error + _m.sent(); + globalPermissionsManager = (_g = client.application) === null || _g === void 0 ? void 0 : _g.commands.permissions; + guildPermissionsManager = (_h = client.guilds.cache.get(testGuildId)) === null || _h === void 0 ? void 0 : _h.commands.permissions; + return [4 /*yield*/, ((_j = client.application) === null || _j === void 0 ? void 0 : _j.commands.permissions.fetch({ guild: testGuildId }))]; + case 7: + originalPermissions = _m.sent(); + // Permissions from global manager + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.add({ + command: globalCommandId, + guild: testGuildId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 8: + // Permissions from global manager + _m.sent(); + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.has({ command: globalCommandId, guild: testGuildId, permissionId: testGuildId }))]; + case 9: + _m.sent(); + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.fetch({ guild: testGuildId }))]; + case 10: + _m.sent(); + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.fetch({ command: globalCommandId, guild: testGuildId }))]; + case 11: + _m.sent(); + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.remove({ command: globalCommandId, guild: testGuildId, roles: [testGuildId] }))]; + case 12: + _m.sent(); + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.remove({ command: globalCommandId, guild: testGuildId, users: [testUserId] }))]; + case 13: + _m.sent(); + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.remove({ + command: globalCommandId, + guild: testGuildId, + roles: [testGuildId], + users: [testUserId] + }))]; + case 14: + _m.sent(); + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.set({ + command: globalCommandId, + guild: testGuildId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 15: + _m.sent(); + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.set({ + guild: testGuildId, + fullPermissions: [{ id: globalCommandId, permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }] + }))]; + case 16: + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.add({ + command: globalCommandId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 17: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.has({ command: globalCommandId, permissionId: testGuildId }))]; + case 18: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.fetch())]; + case 19: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.fetch({ command: globalCommandId }))]; + case 20: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.remove({ command: globalCommandId, roles: [testGuildId] }))]; + case 21: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.remove({ command: globalCommandId, users: [testUserId] }))]; + case 22: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.remove({ command: globalCommandId, roles: [testGuildId], users: [testUserId] }))]; + case 23: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.set({ + command: globalCommandId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 24: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.set({ + fullPermissions: [{ id: globalCommandId, permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }] + }))]; + case 25: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.set({ + command: globalCommandId, + guild: testGuildId, + fullPermissions: [{ id: globalCommandId, permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }] + }))]; + case 26: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.add({ + guild: testGuildId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 27: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.has({ guild: testGuildId, permissionId: testGuildId }))]; + case 28: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.remove({ guild: testGuildId, roles: [testGuildId] }))]; + case 29: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.remove({ guild: testGuildId, users: [testUserId] }))]; + case 30: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.remove({ guild: testGuildId, roles: [testGuildId], users: [testUserId] }))]; + case 31: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.set({ + guild: testGuildId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 32: + // @ts-expect-error + _m.sent(); + // Permissions from guild manager + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.add({ + command: globalCommandId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 33: + // Permissions from guild manager + _m.sent(); + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.has({ command: globalCommandId, permissionId: testGuildId }))]; + case 34: + _m.sent(); + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.fetch({}))]; + case 35: + _m.sent(); + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.fetch({ command: globalCommandId }))]; + case 36: + _m.sent(); + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.remove({ command: globalCommandId, roles: [testGuildId] }))]; + case 37: + _m.sent(); + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.remove({ command: globalCommandId, users: [testUserId] }))]; + case 38: + _m.sent(); + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.remove({ command: globalCommandId, roles: [testGuildId], users: [testUserId] }))]; + case 39: + _m.sent(); + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.set({ + command: globalCommandId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 40: + _m.sent(); + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.set({ + fullPermissions: [{ id: globalCommandId, permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }] + }))]; + case 41: + _m.sent(); + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.add({ + command: globalCommandId, + // @ts-expect-error + guild: testGuildId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 42: + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.has({ command: globalCommandId, guild: testGuildId, permissionId: testGuildId }))]; + case 43: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.fetch({ guild: testGuildId }))]; + case 44: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.fetch({ command: globalCommandId, guild: testGuildId }))]; + case 45: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.remove({ command: globalCommandId, guild: testGuildId, roles: [testGuildId] }))]; + case 46: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.remove({ command: globalCommandId, guild: testGuildId, users: [testUserId] }))]; + case 47: + // @ts-expect-error + _m.sent(); + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.remove({ + command: globalCommandId, + // @ts-expect-error + guild: testGuildId, + roles: [testGuildId], + users: [testUserId] + }))]; + case 48: + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.set({ + command: globalCommandId, + guild: testGuildId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 49: + // @ts-expect-error + _m.sent(); + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.set({ + // @ts-expect-error + guild: testGuildId, + fullPermissions: [{ id: globalCommandId, permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }] + }))]; + case 50: + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.add({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }))]; + case 51: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.has({ permissionId: testGuildId }))]; + case 52: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.remove({ roles: [testGuildId] }))]; + case 53: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.remove({ users: [testUserId] }))]; + case 54: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.remove({ roles: [testGuildId], users: [testUserId] }))]; + case 55: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.set({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }))]; + case 56: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.set({ + command: globalCommandId, + fullPermissions: [{ id: globalCommandId, permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }] + }))]; + case 57: + // @ts-expect-error + _m.sent(); + // Permissions from cached global ApplicationCommand + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.add({ + guild: testGuildId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 58: + // Permissions from cached global ApplicationCommand + _m.sent(); + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.has({ guild: testGuildId, permissionId: testGuildId }))]; + case 59: + _m.sent(); + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.fetch({ guild: testGuildId }))]; + case 60: + _m.sent(); + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.remove({ guild: testGuildId, roles: [testGuildId] }))]; + case 61: + _m.sent(); + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.remove({ guild: testGuildId, users: [testUserId] }))]; + case 62: + _m.sent(); + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.remove({ guild: testGuildId, roles: [testGuildId], users: [testUserId] }))]; + case 63: + _m.sent(); + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.set({ + guild: testGuildId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 64: + _m.sent(); + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.add({ + // @ts-expect-error + command: globalCommandId, + guild: testGuildId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 65: + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.has({ command: globalCommandId, guild: testGuildId, permissionId: testGuildId }))]; + case 66: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.fetch({ command: globalCommandId, guild: testGuildId }))]; + case 67: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.remove({ command: globalCommandId, guild: testGuildId, roles: [testGuildId] }))]; + case 68: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.remove({ command: globalCommandId, guild: testGuildId, users: [testUserId] }))]; + case 69: + // @ts-expect-error + _m.sent(); + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.remove({ + // @ts-expect-error + command: globalCommandId, + guild: testGuildId, + roles: [testGuildId], + users: [testUserId] + }))]; + case 70: + _m.sent(); + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.set({ + // @ts-expect-error + command: globalCommandId, + guild: testGuildId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 71: + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.add({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }))]; + case 72: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.has({ permissionId: testGuildId }))]; + case 73: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.fetch({}))]; + case 74: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.remove({ roles: [testGuildId] }))]; + case 75: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.remove({ users: [testUserId] }))]; + case 76: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.remove({ roles: [testGuildId], users: [testUserId] }))]; + case 77: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.set({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }))]; + case 78: + // @ts-expect-error + _m.sent(); + // Permissions from cached guild ApplicationCommand + return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.add({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }))]; + case 79: + // Permissions from cached guild ApplicationCommand + _m.sent(); + return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.has({ permissionId: testGuildId }))]; + case 80: + _m.sent(); + return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.fetch({}))]; + case 81: + _m.sent(); + return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.remove({ roles: [testGuildId] }))]; + case 82: + _m.sent(); + return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.remove({ users: [testUserId] }))]; + case 83: + _m.sent(); + return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.remove({ roles: [testGuildId], users: [testUserId] }))]; + case 84: + _m.sent(); + return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.set({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }))]; + case 85: + _m.sent(); + return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.add({ + // @ts-expect-error + command: globalCommandId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 86: + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.has({ command: guildCommandId, permissionId: testGuildId }))]; + case 87: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.remove({ command: guildCommandId, roles: [testGuildId] }))]; + case 88: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.remove({ command: guildCommandId, users: [testUserId] }))]; + case 89: + // @ts-expect-error + _m.sent(); + return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.remove({ + // @ts-expect-error + command: guildCommandId, + roles: [testGuildId], + users: [testUserId] + }))]; + case 90: + _m.sent(); + return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.set({ + // @ts-expect-error + command: guildCommandId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 91: + _m.sent(); + return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.add({ + // @ts-expect-error + guild: testGuildId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 92: + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.has({ guild: testGuildId, permissionId: testGuildId }))]; + case 93: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.remove({ guild: testGuildId, roles: [testGuildId] }))]; + case 94: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.remove({ guild: testGuildId, users: [testUserId] }))]; + case 95: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.remove({ guild: testGuildId, roles: [testGuildId], users: [testUserId] }))]; + case 96: + // @ts-expect-error + _m.sent(); + return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.set({ + // @ts-expect-error + guild: testGuildId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 97: + _m.sent(); + return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.add({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }))]; + case 98: + _m.sent(); + return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.has({ permissionId: testGuildId }))]; + case 99: + _m.sent(); + return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.fetch({}))]; + case 100: + _m.sent(); + return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.remove({ roles: [testGuildId] }))]; + case 101: + _m.sent(); + return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.remove({ users: [testUserId] }))]; + case 102: + _m.sent(); + return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.remove({ roles: [testGuildId], users: [testUserId] }))]; + case 103: + _m.sent(); + return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.set({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }))]; + case 104: + _m.sent(); + return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.add({ + // @ts-expect-error + command: globalCommandId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 105: + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.has({ command: guildCommandId, permissionId: testGuildId }))]; + case 106: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.remove({ command: guildCommandId, roles: [testGuildId] }))]; + case 107: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.remove({ command: guildCommandId, users: [testUserId] }))]; + case 108: + // @ts-expect-error + _m.sent(); + return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.remove({ + // @ts-expect-error + command: guildCommandId, + roles: [testGuildId], + users: [testUserId] + }))]; + case 109: + _m.sent(); + return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.set({ + // @ts-expect-error + command: guildCommandId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 110: + _m.sent(); + return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.add({ + // @ts-expect-error + guild: testGuildId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 111: + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.has({ guild: testGuildId, permissionId: testGuildId }))]; + case 112: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.remove({ guild: testGuildId, roles: [testGuildId] }))]; + case 113: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.remove({ guild: testGuildId, users: [testUserId] }))]; + case 114: + // @ts-expect-error + _m.sent(); + // @ts-expect-error + return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.remove({ guild: testGuildId, roles: [testGuildId], users: [testUserId] }))]; + case 115: + // @ts-expect-error + _m.sent(); + return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.set({ + // @ts-expect-error + guild: testGuildId, + permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] + }))]; + case 116: + _m.sent(); + (_k = client.application) === null || _k === void 0 ? void 0 : _k.commands.permissions.set({ + guild: testGuildId, + fullPermissions: (_l = originalPermissions === null || originalPermissions === void 0 ? void 0 : originalPermissions.map(function (permissions, id) { return ({ permissions: permissions, id: id }); })) !== null && _l !== void 0 ? _l : [] + }); + return [2 /*return*/]; + } + }); +}); }); +client.on('guildCreate', function (g) { + var channel = g.channels.cache.random(); + if (!channel) + return; + channel.setName('foo').then(function (updatedChannel) { + console.log("New channel name: " + updatedChannel.name); + }); + // @ts-expect-error no options + assertIsPromiseMember(g.members.add(testUserId)); + // @ts-expect-error no access token + assertIsPromiseMember(g.members.add(testUserId, {})); + // @ts-expect-error invalid role resolvable + assertIsPromiseMember(g.members.add(testUserId, { accessToken: 'totallyRealAccessToken', roles: [g.roles.cache] })); + assertType(g.members.add(testUserId, { accessToken: 'totallyRealAccessToken', fetchWhenExisting: false })); + assertIsPromiseMember(g.members.add(testUserId, { accessToken: 'totallyRealAccessToken' })); + assertIsPromiseMember(g.members.add(testUserId, { + accessToken: 'totallyRealAccessToken', + mute: true, + deaf: false, + roles: [g.roles.cache.first()], + force: true, + fetchWhenExisting: true + })); +}); +client.on('messageReactionRemoveAll', function (message) { return __awaiter(void 0, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + console.log("messageReactionRemoveAll - id: " + message.id + " (" + message.id.length + ")"); + if (!message.partial) return [3 /*break*/, 2]; + return [4 /*yield*/, message.fetch()]; + case 1: + message = _a.sent(); + _a.label = 2; + case 2: + console.log("messageReactionRemoveAll - content: " + message.content); + return [2 /*return*/]; + } + }); +}); }); +client.on('messageCreate', function (message) { return __awaiter(void 0, void 0, void 0, function () { + var channel, attachment, embed, component, _a, buttonCollector_1, buttonCollector, selectMenuCollector, defaultCollector, semiDefaultCollector, semiDefaultCollectorChannel, interactionOptions, webhook; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + channel = message.channel; + assertIsMessage(channel.send('string')); + assertIsMessage(channel.send({})); + assertIsMessage(channel.send({ embeds: [] })); + attachment = new _1.MessageAttachment('file.png'); + embed = new _1.MessageEmbed(); + assertIsMessage(channel.send({ files: [attachment] })); + assertIsMessage(channel.send({ embeds: [embed] })); + assertIsMessage(channel.send({ embeds: [embed], files: [attachment] })); + if (!message.inGuild()) return [3 /*break*/, 3]; + assertType(message); + return [4 /*yield*/, message.awaitMessageComponent({ componentType: 'BUTTON' })]; + case 1: + component = _b.sent(); + assertType(component); + _a = assertType; + return [4 /*yield*/, component.reply({ fetchReply: true })]; + case 2: + _a.apply(void 0, [_b.sent()]); + buttonCollector_1 = message.createMessageComponentCollector({ componentType: 'BUTTON' }); + assertType(buttonCollector_1); + assertType(message.channel); + _b.label = 3; + case 3: + assertType(message.channel); + // @ts-expect-error + assertType(message.channel); + // @ts-expect-error + channel.send(); + // @ts-expect-error + channel.send({ another: 'property' }); + buttonCollector = message.createMessageComponentCollector({ componentType: 'BUTTON' }); + assertType(message.awaitMessageComponent({ componentType: 'BUTTON' })); + assertType(channel.awaitMessageComponent({ componentType: 'BUTTON' })); + assertType(buttonCollector); + selectMenuCollector = message.createMessageComponentCollector({ componentType: 'SELECT_MENU' }); + assertType(message.awaitMessageComponent({ componentType: 'SELECT_MENU' })); + assertType(channel.awaitMessageComponent({ componentType: 'SELECT_MENU' })); + assertType(selectMenuCollector); + defaultCollector = message.createMessageComponentCollector(); + assertType(message.awaitMessageComponent()); + assertType(channel.awaitMessageComponent()); + assertType(defaultCollector); + semiDefaultCollector = message.createMessageComponentCollector({ time: 10000 }); + assertType(semiDefaultCollector); + semiDefaultCollectorChannel = message.createMessageComponentCollector({ time: 10000 }); + assertType(semiDefaultCollectorChannel); + interactionOptions = message.createMessageComponentCollector({ interactionType: 'APPLICATION_COMMAND' }); + // Make sure filter parameters are properly inferred. + message.createMessageComponentCollector({ + filter: function (i) { + assertType(i); + return true; + } + }); + message.createMessageComponentCollector({ + componentType: 'BUTTON', + filter: function (i) { + assertType(i); + return true; + } + }); + message.createMessageComponentCollector({ + componentType: 'SELECT_MENU', + filter: function (i) { + assertType(i); + return true; + } + }); + message.awaitMessageComponent({ + filter: function (i) { + assertType(i); + return true; + } + }); + message.awaitMessageComponent({ + componentType: 'BUTTON', + filter: function (i) { + assertType(i); + return true; + } + }); + message.awaitMessageComponent({ + componentType: 'SELECT_MENU', + filter: function (i) { + assertType(i); + return true; + } + }); + return [4 /*yield*/, message.fetchWebhook()]; + case 4: + webhook = _b.sent(); + if (webhook.isChannelFollower()) { + assertType(webhook.sourceGuild); + assertType(webhook.sourceChannel); + } + else if (webhook.isIncoming()) { + assertType(webhook.token); + } + // @ts-expect-error + assertType(webhook.sourceGuild); + // @ts-expect-error + assertType(webhook.sourceChannel); + // @ts-expect-error + assertType(webhook.token); + channel.awaitMessageComponent({ + filter: function (i) { + assertType(i); + return true; + } + }); + channel.awaitMessageComponent({ + componentType: 'BUTTON', + filter: function (i) { + assertType(i); + return true; + } + }); + channel.awaitMessageComponent({ + componentType: 'SELECT_MENU', + filter: function (i) { + assertType(i); + return true; + } + }); + return [2 /*return*/]; + } + }); +}); }); +client.on('interaction', function (interaction) { return __awaiter(void 0, void 0, void 0, function () { + var button, actionRow; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + assertType(interaction.guildId); + assertType(interaction.channelId); + assertType(interaction.member); + if (!interaction.isCommand()) + return [2 /*return*/]; + void new _1.MessageActionRow(); + button = new _1.MessageButton(); + actionRow = new _1.MessageActionRow({ components: [button] }); + return [4 /*yield*/, interaction.reply({ content: 'Hi!', components: [actionRow] })]; + case 1: + _a.sent(); + // @ts-expect-error + return [4 /*yield*/, interaction.reply({ content: 'Hi!', components: [[button]] })]; + case 2: + // @ts-expect-error + _a.sent(); + // @ts-expect-error + void new _1.MessageActionRow({}); + // @ts-expect-error + return [4 /*yield*/, interaction.reply({ content: 'Hi!', components: [button] })]; + case 3: + // @ts-expect-error + _a.sent(); + if (interaction.isMessageComponent()) { + assertType(interaction.channelId); + } + return [2 /*return*/]; + } + }); +}); }); +client.login('absolutely-valid-token'); +// Test client conditional types +client.on('ready', function (client) { + assertType(client); +}); +assertType(loggedInClient.application); +assertType(loggedInClient.readyAt); +assertType(loggedInClient.readyTimestamp); +assertType(loggedInClient.token); +assertType(loggedInClient.uptime); +assertType(loggedInClient.user); +assertType(loggedOutClient.application); +assertType(loggedOutClient.readyAt); +assertType(loggedOutClient.readyTimestamp); +assertType(loggedOutClient.token); +assertType(loggedOutClient.uptime); +assertType(loggedOutClient.user); +assertType(serialize(undefined)); +assertType(serialize(null)); +assertType(serialize([1, 2, 3])); +assertType(serialize(new Set([1, 2, 3]))); +assertType(serialize(new Map([ + [1, '2'], + [2, '4'], +]))); +assertType(serialize(new _1.Permissions(_1.Permissions.FLAGS.ATTACH_FILES))); +assertType(serialize(new _1.Intents(_1.Intents.FLAGS.GUILDS))); +assertType(serialize(new _1.Collection([ + [1, '2'], + [2, '4'], +]))); +assertType(serialize(Symbol('a'))); +assertType(serialize(function () { })); +assertType(serialize(BigInt(42))); +assertType(shardingManager.broadcastEval(function () { return 1; })); +assertType(shardClientUtil.broadcastEval(function () { return 1; })); +assertType(shardingManager.broadcastEval(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { + return [2 /*return*/, 1]; +}); }); })); +assertType(shardClientUtil.broadcastEval(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { + return [2 /*return*/, 1]; +}); }); })); +// Test whether the structures implement send +assertType(dmChannel.send); +assertType(threadChannel); +assertType(newsChannel); +assertType(textChannel); +assertType(user); +assertType(guildMember); +assertType(dmChannel.lastMessage); +assertType(threadChannel.lastMessage); +assertType(newsChannel.lastMessage); +assertType(textChannel.lastMessage); +notPropertyOf(user, 'lastMessage'); +notPropertyOf(user, 'lastMessageId'); +notPropertyOf(guildMember, 'lastMessage'); +notPropertyOf(guildMember, 'lastMessageId'); +messageCollector.on('collect', function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + assertType(args); +}); +reactionCollector.on('dispose', function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + assertType(args); +}); +// Make sure the properties are typed correctly, and that no backwards properties +// (K -> V and V -> K) exist: +assertType(_1.Constants.Events.MESSAGE_CREATE); +assertType(_1.Constants.ShardEvents.CLOSE); +assertType(_1.Constants.Status.CONNECTING); +assertType(_1.Constants.Opcodes.DISPATCH); +assertType(_1.Constants.ClientApplicationAssetTypes.BIG); +{ + assertType(applicationCommandManager.create(applicationCommandData)); + assertType(applicationCommandManager.create(applicationCommandData, '0')); + assertType(applicationCommandManager.edit(applicationCommandResolvable, applicationCommandData)); + assertType(applicationCommandManager.edit(applicationCommandResolvable, applicationCommandData, '0')); + assertType(applicationCommandManager.set([applicationCommandData])); + assertType(applicationCommandManager.set([applicationCommandData], '0')); +} +{ + // Options aren't allowed on this command type. + // @ts-expect-error + applicationNonChoiceOptionData.choices; +} +{ + // Choices should be available. + applicationChoiceOptionData.choices; +} +{ + assertType(applicationSubGroupCommandData.type); + assertType(applicationSubGroupCommandData.options); +} +{ + assertType(applicationSubCommandData.type); + // Check that only subcommands can have no subcommand or subcommand group sub-options. + assertType(applicationSubCommandData.options); +} +assertType(guildApplicationCommandManager.fetch()); +assertType(guildApplicationCommandManager.fetch(undefined, {})); +assertType(guildApplicationCommandManager.fetch('0')); +{ + assertType(guildChannelManager.create('name', { type: 'GUILD_VOICE' })); + assertType(guildChannelManager.create('name', { type: 'GUILD_CATEGORY' })); + assertType(guildChannelManager.create('name', { type: 'GUILD_TEXT' })); + assertType(guildChannelManager.create('name', { type: 'GUILD_NEWS' })); + assertType(guildChannelManager.create('name', { type: 'GUILD_STORE' })); + assertType(guildChannelManager.create('name', { type: 'GUILD_STAGE_VOICE' })); + assertType(guildChannelManager.fetch()); + assertType(guildChannelManager.fetch(undefined, {})); + assertType(guildChannelManager.fetch('0')); +} +assertType(roleManager.fetch()); +assertType(roleManager.fetch(undefined, {})); +assertType(roleManager.fetch('0')); +assertType(guildEmojiManager.fetch()); +assertType(guildEmojiManager.fetch(undefined, {})); +assertType(guildEmojiManager.fetch('0')); +assertType(typing.user); +if (typing.user.partial) + assertType(typing.user.username); +assertType(typing.channel); +if (typing.channel.partial) + assertType(typing.channel.lastMessageId); +assertType(typing.member); +assertType(typing.guild); +if (typing.inGuild()) { + assertType(typing.channel.guild); + assertType(typing.guild); +} +// Test partials structures +client.on('guildMemberRemove', function (member) { + if (member.partial) + return assertType(member.joinedAt); + assertType(member.joinedAt); +}); +client.on('messageReactionAdd', function (reaction) { return __awaiter(void 0, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!reaction.partial) return [3 /*break*/, 2]; + assertType(reaction.count); + return [4 /*yield*/, reaction.fetch()]; + case 1: + reaction = _a.sent(); + _a.label = 2; + case 2: + assertType(reaction.count); + if (reaction.message.partial) + return [2 /*return*/, assertType(reaction.message.content)]; + assertType(reaction.message.content); + return [2 /*return*/]; + } + }); +}); }); +if (interaction.inGuild()) + assertType(interaction.guildId); +client.on('interactionCreate', function (interaction) { return __awaiter(void 0, void 0, void 0, function () { + var msg, btn, optionalOption, requiredOption; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (interaction.inCachedGuild()) { + assertType(interaction.member); + // @ts-expect-error + assertType(interaction); + assertType(interaction); + } + else if (interaction.inRawGuild()) { + assertType(interaction.member); + // @ts-expect-error + consumeCachedInteraction(interaction); + } + else { + assertType(interaction.member); + // @ts-expect-error + consumeCachedInteraction(interaction); + } + if (interaction.isContextMenu()) { + assertType(interaction); + if (interaction.inCachedGuild()) { + assertType(interaction); + assertType(interaction.guild); + assertType(interaction); + } + else if (interaction.inRawGuild()) { + assertType(interaction); + assertType(interaction.guild); + } + else if (interaction.inGuild()) { + assertType(interaction); + assertType(interaction.guild); + } + } + if (interaction.isButton()) { + assertType(interaction); + if (interaction.inCachedGuild()) { + assertType(interaction); + assertType(interaction.guild); + assertType(interaction.reply({ fetchReply: true })); + } + else if (interaction.inRawGuild()) { + assertType(interaction); + assertType(interaction.guild); + assertType(interaction.reply({ fetchReply: true })); + } + else if (interaction.inGuild()) { + assertType(interaction); + assertType(interaction.guild); + assertType(interaction.reply({ fetchReply: true })); + } + } + if (interaction.isMessageComponent()) { + assertType(interaction); + if (interaction.inCachedGuild()) { + assertType(interaction); + assertType(interaction.guild); + assertType(interaction.reply({ fetchReply: true })); + } + else if (interaction.inRawGuild()) { + assertType(interaction); + assertType(interaction.guild); + assertType(interaction.reply({ fetchReply: true })); + } + else if (interaction.inGuild()) { + assertType(interaction); + assertType(interaction.guild); + assertType(interaction.reply({ fetchReply: true })); + } + } + if (interaction.isSelectMenu()) { + assertType(interaction); + if (interaction.inCachedGuild()) { + assertType(interaction); + assertType(interaction.guild); + assertType(interaction.reply({ fetchReply: true })); + } + else if (interaction.inRawGuild()) { + assertType(interaction); + assertType(interaction.guild); + assertType(interaction.reply({ fetchReply: true })); + } + else if (interaction.inGuild()) { + assertType(interaction); + assertType(interaction.guild); + assertType(interaction.reply({ fetchReply: true })); + } + } + if (!interaction.isCommand()) return [3 /*break*/, 6]; + if (!interaction.inRawGuild()) return [3 /*break*/, 1]; + // @ts-expect-error + consumeCachedCommand(interaction); + assertType(interaction); + assertType(interaction.reply({ fetchReply: true })); + assertType(interaction.options.getMember('test')); + assertType(interaction.options.getMember('test', true)); + assertType(interaction.options.getChannel('test', true)); + assertType(interaction.options.getRole('test', true)); + assertType(interaction.options.getMessage('test', true)); + return [3 /*break*/, 5]; + case 1: + if (!interaction.inCachedGuild()) return [3 /*break*/, 4]; + return [4 /*yield*/, interaction.reply({ fetchReply: true })]; + case 2: + msg = _a.sent(); + return [4 /*yield*/, msg.awaitMessageComponent({ componentType: 'BUTTON' })]; + case 3: + btn = _a.sent(); + assertType(msg); + assertType(btn); + assertType(interaction); + assertType(interaction.options.getMember('test', true)); + assertType(interaction.options.getMember('test')); + assertType(interaction); + assertType(interaction.reply({ fetchReply: true })); + assertType(interaction.options.getChannel('test', true)); + assertType(interaction.options.getRole('test', true)); + assertType(interaction.options.getMessage('test', true)); + return [3 /*break*/, 5]; + case 4: + // @ts-expect-error + consumeCachedCommand(interaction); + assertType(interaction); + assertType(interaction.reply({ fetchReply: true })); + assertType(interaction.options.getMember('test')); + assertType(interaction.options.getMember('test', true)); + assertType(interaction.options.getChannel('test', true)); + assertType(interaction.options.getRole('test', true)); + assertType(interaction.options.getMessage('test', true)); + _a.label = 5; + case 5: + assertType(interaction); + assertType(interaction.options); + assertType(interaction.options.data); + optionalOption = interaction.options.get('name'); + requiredOption = interaction.options.get('name', true); + assertType(optionalOption); + assertType(requiredOption); + assertType(requiredOption.options); + assertType(interaction.options.getString('name', booleanValue)); + assertType(interaction.options.getString('name', false)); + assertType(interaction.options.getString('name', true)); + assertType(interaction.options.getSubcommand()); + assertType(interaction.options.getSubcommand(true)); + assertType(interaction.options.getSubcommand(booleanValue)); + assertType(interaction.options.getSubcommand(false)); + assertType(interaction.options.getSubcommandGroup()); + assertType(interaction.options.getSubcommandGroup(true)); + assertType(interaction.options.getSubcommandGroup(booleanValue)); + assertType(interaction.options.getSubcommandGroup(false)); + _a.label = 6; + case 6: return [2 /*return*/]; + } + }); +}); }); diff --git a/typings/tests.ts b/typings/tests.ts index 4f5a11c21d3c..5cb77954a695 100644 --- a/typings/tests.ts +++ b/typings/tests.ts @@ -19,6 +19,7 @@ import { ApplicationCommandResolvable, ApplicationCommandSubCommandData, ApplicationCommandSubGroupData, + BaseCommandInteraction, ButtonInteraction, CacheType, CategoryChannel, @@ -922,7 +923,7 @@ client.on('interactionCreate', async interaction => { if (interaction.inCachedGuild()) { assertType(interaction); assertType(interaction.guild); - assertType>(interaction); + assertType>(interaction); } else if (interaction.inRawGuild()) { assertType(interaction); assertType(interaction.guild); From cc479aba84dca487d811e5f6e80490011625992b Mon Sep 17 00:00:00 2001 From: Suneet Tipirneni Date: Thu, 28 Oct 2021 15:39:48 -0400 Subject: [PATCH 50/50] fix: remove js file --- typings/tests.js | 1205 ---------------------------------------------- 1 file changed, 1205 deletions(-) delete mode 100644 typings/tests.js diff --git a/typings/tests.js b/typings/tests.js deleted file mode 100644 index 2a500f7b11cc..000000000000 --- a/typings/tests.js +++ /dev/null @@ -1,1205 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -exports.__esModule = true; -var _1 = require("."); -var client = new _1.Client({ - intents: _1.Intents.FLAGS.GUILDS, - makeCache: _1.Options.cacheWithLimits({ - MessageManager: 200, - // @ts-expect-error - Message: 100, - ThreadManager: { - maxSize: 1000, - keepOverLimit: function (x) { return x.id === '123'; }, - sweepInterval: 5000, - sweepFilter: _1.LimitedCollection.filterByLifetime({ - getComparisonTimestamp: function (x) { var _a; return (_a = x.archiveTimestamp) !== null && _a !== void 0 ? _a : 0; }, - excludeFromSweep: function (x) { return !x.archived; } - }) - } - }) -}); -var testGuildId = '222078108977594368'; // DJS -var testUserId = '987654321098765432'; // example id -var globalCommandId = '123456789012345678'; // example id -var guildCommandId = '234567890123456789'; // example id -client.on('ready', function () { return __awaiter(void 0, void 0, void 0, function () { - var _a, _b, globalCommand, guildCommandFromGlobal, guildCommandFromGuild, globalPermissionsManager, guildPermissionsManager, originalPermissions; - var _c, _d, _e, _f, _g, _h, _j, _k, _l; - return __generator(this, function (_m) { - switch (_m.label) { - case 0: - console.log("Client is logged in as " + client.user.tag + " and ready!"); - // Test fetching all global commands and ones from one guild - _a = assertType; - return [4 /*yield*/, client.application.commands.fetch()]; - case 1: - // Test fetching all global commands and ones from one guild - _a.apply(void 0, [_m.sent()]); - _b = assertType; - return [4 /*yield*/, client.application.commands.fetch({ guildId: testGuildId })]; - case 2: - _b.apply(void 0, [_m.sent()]); - return [4 /*yield*/, ((_c = client.application) === null || _c === void 0 ? void 0 : _c.commands.fetch(globalCommandId))]; - case 3: - globalCommand = _m.sent(); - return [4 /*yield*/, ((_d = client.application) === null || _d === void 0 ? void 0 : _d.commands.fetch(guildCommandId, { guildId: testGuildId }))]; - case 4: - guildCommandFromGlobal = _m.sent(); - return [4 /*yield*/, ((_e = client.guilds.cache.get(testGuildId)) === null || _e === void 0 ? void 0 : _e.commands.fetch(guildCommandId))]; - case 5: - guildCommandFromGuild = _m.sent(); - // @ts-expect-error - return [4 /*yield*/, ((_f = client.guilds.cache.get(testGuildId)) === null || _f === void 0 ? void 0 : _f.commands.fetch(guildCommandId, { guildId: testGuildId }))]; - case 6: - // @ts-expect-error - _m.sent(); - globalPermissionsManager = (_g = client.application) === null || _g === void 0 ? void 0 : _g.commands.permissions; - guildPermissionsManager = (_h = client.guilds.cache.get(testGuildId)) === null || _h === void 0 ? void 0 : _h.commands.permissions; - return [4 /*yield*/, ((_j = client.application) === null || _j === void 0 ? void 0 : _j.commands.permissions.fetch({ guild: testGuildId }))]; - case 7: - originalPermissions = _m.sent(); - // Permissions from global manager - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.add({ - command: globalCommandId, - guild: testGuildId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 8: - // Permissions from global manager - _m.sent(); - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.has({ command: globalCommandId, guild: testGuildId, permissionId: testGuildId }))]; - case 9: - _m.sent(); - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.fetch({ guild: testGuildId }))]; - case 10: - _m.sent(); - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.fetch({ command: globalCommandId, guild: testGuildId }))]; - case 11: - _m.sent(); - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.remove({ command: globalCommandId, guild: testGuildId, roles: [testGuildId] }))]; - case 12: - _m.sent(); - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.remove({ command: globalCommandId, guild: testGuildId, users: [testUserId] }))]; - case 13: - _m.sent(); - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.remove({ - command: globalCommandId, - guild: testGuildId, - roles: [testGuildId], - users: [testUserId] - }))]; - case 14: - _m.sent(); - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.set({ - command: globalCommandId, - guild: testGuildId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 15: - _m.sent(); - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.set({ - guild: testGuildId, - fullPermissions: [{ id: globalCommandId, permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }] - }))]; - case 16: - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.add({ - command: globalCommandId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 17: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.has({ command: globalCommandId, permissionId: testGuildId }))]; - case 18: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.fetch())]; - case 19: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.fetch({ command: globalCommandId }))]; - case 20: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.remove({ command: globalCommandId, roles: [testGuildId] }))]; - case 21: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.remove({ command: globalCommandId, users: [testUserId] }))]; - case 22: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.remove({ command: globalCommandId, roles: [testGuildId], users: [testUserId] }))]; - case 23: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.set({ - command: globalCommandId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 24: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.set({ - fullPermissions: [{ id: globalCommandId, permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }] - }))]; - case 25: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.set({ - command: globalCommandId, - guild: testGuildId, - fullPermissions: [{ id: globalCommandId, permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }] - }))]; - case 26: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.add({ - guild: testGuildId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 27: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.has({ guild: testGuildId, permissionId: testGuildId }))]; - case 28: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.remove({ guild: testGuildId, roles: [testGuildId] }))]; - case 29: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.remove({ guild: testGuildId, users: [testUserId] }))]; - case 30: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.remove({ guild: testGuildId, roles: [testGuildId], users: [testUserId] }))]; - case 31: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalPermissionsManager === null || globalPermissionsManager === void 0 ? void 0 : globalPermissionsManager.set({ - guild: testGuildId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 32: - // @ts-expect-error - _m.sent(); - // Permissions from guild manager - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.add({ - command: globalCommandId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 33: - // Permissions from guild manager - _m.sent(); - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.has({ command: globalCommandId, permissionId: testGuildId }))]; - case 34: - _m.sent(); - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.fetch({}))]; - case 35: - _m.sent(); - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.fetch({ command: globalCommandId }))]; - case 36: - _m.sent(); - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.remove({ command: globalCommandId, roles: [testGuildId] }))]; - case 37: - _m.sent(); - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.remove({ command: globalCommandId, users: [testUserId] }))]; - case 38: - _m.sent(); - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.remove({ command: globalCommandId, roles: [testGuildId], users: [testUserId] }))]; - case 39: - _m.sent(); - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.set({ - command: globalCommandId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 40: - _m.sent(); - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.set({ - fullPermissions: [{ id: globalCommandId, permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }] - }))]; - case 41: - _m.sent(); - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.add({ - command: globalCommandId, - // @ts-expect-error - guild: testGuildId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 42: - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.has({ command: globalCommandId, guild: testGuildId, permissionId: testGuildId }))]; - case 43: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.fetch({ guild: testGuildId }))]; - case 44: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.fetch({ command: globalCommandId, guild: testGuildId }))]; - case 45: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.remove({ command: globalCommandId, guild: testGuildId, roles: [testGuildId] }))]; - case 46: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.remove({ command: globalCommandId, guild: testGuildId, users: [testUserId] }))]; - case 47: - // @ts-expect-error - _m.sent(); - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.remove({ - command: globalCommandId, - // @ts-expect-error - guild: testGuildId, - roles: [testGuildId], - users: [testUserId] - }))]; - case 48: - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.set({ - command: globalCommandId, - guild: testGuildId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 49: - // @ts-expect-error - _m.sent(); - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.set({ - // @ts-expect-error - guild: testGuildId, - fullPermissions: [{ id: globalCommandId, permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }] - }))]; - case 50: - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.add({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }))]; - case 51: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.has({ permissionId: testGuildId }))]; - case 52: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.remove({ roles: [testGuildId] }))]; - case 53: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.remove({ users: [testUserId] }))]; - case 54: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.remove({ roles: [testGuildId], users: [testUserId] }))]; - case 55: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.set({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }))]; - case 56: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildPermissionsManager === null || guildPermissionsManager === void 0 ? void 0 : guildPermissionsManager.set({ - command: globalCommandId, - fullPermissions: [{ id: globalCommandId, permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }] - }))]; - case 57: - // @ts-expect-error - _m.sent(); - // Permissions from cached global ApplicationCommand - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.add({ - guild: testGuildId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 58: - // Permissions from cached global ApplicationCommand - _m.sent(); - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.has({ guild: testGuildId, permissionId: testGuildId }))]; - case 59: - _m.sent(); - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.fetch({ guild: testGuildId }))]; - case 60: - _m.sent(); - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.remove({ guild: testGuildId, roles: [testGuildId] }))]; - case 61: - _m.sent(); - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.remove({ guild: testGuildId, users: [testUserId] }))]; - case 62: - _m.sent(); - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.remove({ guild: testGuildId, roles: [testGuildId], users: [testUserId] }))]; - case 63: - _m.sent(); - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.set({ - guild: testGuildId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 64: - _m.sent(); - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.add({ - // @ts-expect-error - command: globalCommandId, - guild: testGuildId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 65: - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.has({ command: globalCommandId, guild: testGuildId, permissionId: testGuildId }))]; - case 66: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.fetch({ command: globalCommandId, guild: testGuildId }))]; - case 67: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.remove({ command: globalCommandId, guild: testGuildId, roles: [testGuildId] }))]; - case 68: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.remove({ command: globalCommandId, guild: testGuildId, users: [testUserId] }))]; - case 69: - // @ts-expect-error - _m.sent(); - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.remove({ - // @ts-expect-error - command: globalCommandId, - guild: testGuildId, - roles: [testGuildId], - users: [testUserId] - }))]; - case 70: - _m.sent(); - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.set({ - // @ts-expect-error - command: globalCommandId, - guild: testGuildId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 71: - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.add({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }))]; - case 72: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.has({ permissionId: testGuildId }))]; - case 73: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.fetch({}))]; - case 74: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.remove({ roles: [testGuildId] }))]; - case 75: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.remove({ users: [testUserId] }))]; - case 76: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.remove({ roles: [testGuildId], users: [testUserId] }))]; - case 77: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (globalCommand === null || globalCommand === void 0 ? void 0 : globalCommand.permissions.set({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }))]; - case 78: - // @ts-expect-error - _m.sent(); - // Permissions from cached guild ApplicationCommand - return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.add({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }))]; - case 79: - // Permissions from cached guild ApplicationCommand - _m.sent(); - return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.has({ permissionId: testGuildId }))]; - case 80: - _m.sent(); - return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.fetch({}))]; - case 81: - _m.sent(); - return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.remove({ roles: [testGuildId] }))]; - case 82: - _m.sent(); - return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.remove({ users: [testUserId] }))]; - case 83: - _m.sent(); - return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.remove({ roles: [testGuildId], users: [testUserId] }))]; - case 84: - _m.sent(); - return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.set({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }))]; - case 85: - _m.sent(); - return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.add({ - // @ts-expect-error - command: globalCommandId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 86: - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.has({ command: guildCommandId, permissionId: testGuildId }))]; - case 87: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.remove({ command: guildCommandId, roles: [testGuildId] }))]; - case 88: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.remove({ command: guildCommandId, users: [testUserId] }))]; - case 89: - // @ts-expect-error - _m.sent(); - return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.remove({ - // @ts-expect-error - command: guildCommandId, - roles: [testGuildId], - users: [testUserId] - }))]; - case 90: - _m.sent(); - return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.set({ - // @ts-expect-error - command: guildCommandId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 91: - _m.sent(); - return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.add({ - // @ts-expect-error - guild: testGuildId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 92: - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.has({ guild: testGuildId, permissionId: testGuildId }))]; - case 93: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.remove({ guild: testGuildId, roles: [testGuildId] }))]; - case 94: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.remove({ guild: testGuildId, users: [testUserId] }))]; - case 95: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.remove({ guild: testGuildId, roles: [testGuildId], users: [testUserId] }))]; - case 96: - // @ts-expect-error - _m.sent(); - return [4 /*yield*/, (guildCommandFromGlobal === null || guildCommandFromGlobal === void 0 ? void 0 : guildCommandFromGlobal.permissions.set({ - // @ts-expect-error - guild: testGuildId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 97: - _m.sent(); - return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.add({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }))]; - case 98: - _m.sent(); - return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.has({ permissionId: testGuildId }))]; - case 99: - _m.sent(); - return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.fetch({}))]; - case 100: - _m.sent(); - return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.remove({ roles: [testGuildId] }))]; - case 101: - _m.sent(); - return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.remove({ users: [testUserId] }))]; - case 102: - _m.sent(); - return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.remove({ roles: [testGuildId], users: [testUserId] }))]; - case 103: - _m.sent(); - return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.set({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }))]; - case 104: - _m.sent(); - return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.add({ - // @ts-expect-error - command: globalCommandId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 105: - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.has({ command: guildCommandId, permissionId: testGuildId }))]; - case 106: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.remove({ command: guildCommandId, roles: [testGuildId] }))]; - case 107: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.remove({ command: guildCommandId, users: [testUserId] }))]; - case 108: - // @ts-expect-error - _m.sent(); - return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.remove({ - // @ts-expect-error - command: guildCommandId, - roles: [testGuildId], - users: [testUserId] - }))]; - case 109: - _m.sent(); - return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.set({ - // @ts-expect-error - command: guildCommandId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 110: - _m.sent(); - return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.add({ - // @ts-expect-error - guild: testGuildId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 111: - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.has({ guild: testGuildId, permissionId: testGuildId }))]; - case 112: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.remove({ guild: testGuildId, roles: [testGuildId] }))]; - case 113: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.remove({ guild: testGuildId, users: [testUserId] }))]; - case 114: - // @ts-expect-error - _m.sent(); - // @ts-expect-error - return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.remove({ guild: testGuildId, roles: [testGuildId], users: [testUserId] }))]; - case 115: - // @ts-expect-error - _m.sent(); - return [4 /*yield*/, (guildCommandFromGuild === null || guildCommandFromGuild === void 0 ? void 0 : guildCommandFromGuild.permissions.set({ - // @ts-expect-error - guild: testGuildId, - permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] - }))]; - case 116: - _m.sent(); - (_k = client.application) === null || _k === void 0 ? void 0 : _k.commands.permissions.set({ - guild: testGuildId, - fullPermissions: (_l = originalPermissions === null || originalPermissions === void 0 ? void 0 : originalPermissions.map(function (permissions, id) { return ({ permissions: permissions, id: id }); })) !== null && _l !== void 0 ? _l : [] - }); - return [2 /*return*/]; - } - }); -}); }); -client.on('guildCreate', function (g) { - var channel = g.channels.cache.random(); - if (!channel) - return; - channel.setName('foo').then(function (updatedChannel) { - console.log("New channel name: " + updatedChannel.name); - }); - // @ts-expect-error no options - assertIsPromiseMember(g.members.add(testUserId)); - // @ts-expect-error no access token - assertIsPromiseMember(g.members.add(testUserId, {})); - // @ts-expect-error invalid role resolvable - assertIsPromiseMember(g.members.add(testUserId, { accessToken: 'totallyRealAccessToken', roles: [g.roles.cache] })); - assertType(g.members.add(testUserId, { accessToken: 'totallyRealAccessToken', fetchWhenExisting: false })); - assertIsPromiseMember(g.members.add(testUserId, { accessToken: 'totallyRealAccessToken' })); - assertIsPromiseMember(g.members.add(testUserId, { - accessToken: 'totallyRealAccessToken', - mute: true, - deaf: false, - roles: [g.roles.cache.first()], - force: true, - fetchWhenExisting: true - })); -}); -client.on('messageReactionRemoveAll', function (message) { return __awaiter(void 0, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - console.log("messageReactionRemoveAll - id: " + message.id + " (" + message.id.length + ")"); - if (!message.partial) return [3 /*break*/, 2]; - return [4 /*yield*/, message.fetch()]; - case 1: - message = _a.sent(); - _a.label = 2; - case 2: - console.log("messageReactionRemoveAll - content: " + message.content); - return [2 /*return*/]; - } - }); -}); }); -client.on('messageCreate', function (message) { return __awaiter(void 0, void 0, void 0, function () { - var channel, attachment, embed, component, _a, buttonCollector_1, buttonCollector, selectMenuCollector, defaultCollector, semiDefaultCollector, semiDefaultCollectorChannel, interactionOptions, webhook; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - channel = message.channel; - assertIsMessage(channel.send('string')); - assertIsMessage(channel.send({})); - assertIsMessage(channel.send({ embeds: [] })); - attachment = new _1.MessageAttachment('file.png'); - embed = new _1.MessageEmbed(); - assertIsMessage(channel.send({ files: [attachment] })); - assertIsMessage(channel.send({ embeds: [embed] })); - assertIsMessage(channel.send({ embeds: [embed], files: [attachment] })); - if (!message.inGuild()) return [3 /*break*/, 3]; - assertType(message); - return [4 /*yield*/, message.awaitMessageComponent({ componentType: 'BUTTON' })]; - case 1: - component = _b.sent(); - assertType(component); - _a = assertType; - return [4 /*yield*/, component.reply({ fetchReply: true })]; - case 2: - _a.apply(void 0, [_b.sent()]); - buttonCollector_1 = message.createMessageComponentCollector({ componentType: 'BUTTON' }); - assertType(buttonCollector_1); - assertType(message.channel); - _b.label = 3; - case 3: - assertType(message.channel); - // @ts-expect-error - assertType(message.channel); - // @ts-expect-error - channel.send(); - // @ts-expect-error - channel.send({ another: 'property' }); - buttonCollector = message.createMessageComponentCollector({ componentType: 'BUTTON' }); - assertType(message.awaitMessageComponent({ componentType: 'BUTTON' })); - assertType(channel.awaitMessageComponent({ componentType: 'BUTTON' })); - assertType(buttonCollector); - selectMenuCollector = message.createMessageComponentCollector({ componentType: 'SELECT_MENU' }); - assertType(message.awaitMessageComponent({ componentType: 'SELECT_MENU' })); - assertType(channel.awaitMessageComponent({ componentType: 'SELECT_MENU' })); - assertType(selectMenuCollector); - defaultCollector = message.createMessageComponentCollector(); - assertType(message.awaitMessageComponent()); - assertType(channel.awaitMessageComponent()); - assertType(defaultCollector); - semiDefaultCollector = message.createMessageComponentCollector({ time: 10000 }); - assertType(semiDefaultCollector); - semiDefaultCollectorChannel = message.createMessageComponentCollector({ time: 10000 }); - assertType(semiDefaultCollectorChannel); - interactionOptions = message.createMessageComponentCollector({ interactionType: 'APPLICATION_COMMAND' }); - // Make sure filter parameters are properly inferred. - message.createMessageComponentCollector({ - filter: function (i) { - assertType(i); - return true; - } - }); - message.createMessageComponentCollector({ - componentType: 'BUTTON', - filter: function (i) { - assertType(i); - return true; - } - }); - message.createMessageComponentCollector({ - componentType: 'SELECT_MENU', - filter: function (i) { - assertType(i); - return true; - } - }); - message.awaitMessageComponent({ - filter: function (i) { - assertType(i); - return true; - } - }); - message.awaitMessageComponent({ - componentType: 'BUTTON', - filter: function (i) { - assertType(i); - return true; - } - }); - message.awaitMessageComponent({ - componentType: 'SELECT_MENU', - filter: function (i) { - assertType(i); - return true; - } - }); - return [4 /*yield*/, message.fetchWebhook()]; - case 4: - webhook = _b.sent(); - if (webhook.isChannelFollower()) { - assertType(webhook.sourceGuild); - assertType(webhook.sourceChannel); - } - else if (webhook.isIncoming()) { - assertType(webhook.token); - } - // @ts-expect-error - assertType(webhook.sourceGuild); - // @ts-expect-error - assertType(webhook.sourceChannel); - // @ts-expect-error - assertType(webhook.token); - channel.awaitMessageComponent({ - filter: function (i) { - assertType(i); - return true; - } - }); - channel.awaitMessageComponent({ - componentType: 'BUTTON', - filter: function (i) { - assertType(i); - return true; - } - }); - channel.awaitMessageComponent({ - componentType: 'SELECT_MENU', - filter: function (i) { - assertType(i); - return true; - } - }); - return [2 /*return*/]; - } - }); -}); }); -client.on('interaction', function (interaction) { return __awaiter(void 0, void 0, void 0, function () { - var button, actionRow; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - assertType(interaction.guildId); - assertType(interaction.channelId); - assertType(interaction.member); - if (!interaction.isCommand()) - return [2 /*return*/]; - void new _1.MessageActionRow(); - button = new _1.MessageButton(); - actionRow = new _1.MessageActionRow({ components: [button] }); - return [4 /*yield*/, interaction.reply({ content: 'Hi!', components: [actionRow] })]; - case 1: - _a.sent(); - // @ts-expect-error - return [4 /*yield*/, interaction.reply({ content: 'Hi!', components: [[button]] })]; - case 2: - // @ts-expect-error - _a.sent(); - // @ts-expect-error - void new _1.MessageActionRow({}); - // @ts-expect-error - return [4 /*yield*/, interaction.reply({ content: 'Hi!', components: [button] })]; - case 3: - // @ts-expect-error - _a.sent(); - if (interaction.isMessageComponent()) { - assertType(interaction.channelId); - } - return [2 /*return*/]; - } - }); -}); }); -client.login('absolutely-valid-token'); -// Test client conditional types -client.on('ready', function (client) { - assertType(client); -}); -assertType(loggedInClient.application); -assertType(loggedInClient.readyAt); -assertType(loggedInClient.readyTimestamp); -assertType(loggedInClient.token); -assertType(loggedInClient.uptime); -assertType(loggedInClient.user); -assertType(loggedOutClient.application); -assertType(loggedOutClient.readyAt); -assertType(loggedOutClient.readyTimestamp); -assertType(loggedOutClient.token); -assertType(loggedOutClient.uptime); -assertType(loggedOutClient.user); -assertType(serialize(undefined)); -assertType(serialize(null)); -assertType(serialize([1, 2, 3])); -assertType(serialize(new Set([1, 2, 3]))); -assertType(serialize(new Map([ - [1, '2'], - [2, '4'], -]))); -assertType(serialize(new _1.Permissions(_1.Permissions.FLAGS.ATTACH_FILES))); -assertType(serialize(new _1.Intents(_1.Intents.FLAGS.GUILDS))); -assertType(serialize(new _1.Collection([ - [1, '2'], - [2, '4'], -]))); -assertType(serialize(Symbol('a'))); -assertType(serialize(function () { })); -assertType(serialize(BigInt(42))); -assertType(shardingManager.broadcastEval(function () { return 1; })); -assertType(shardClientUtil.broadcastEval(function () { return 1; })); -assertType(shardingManager.broadcastEval(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { - return [2 /*return*/, 1]; -}); }); })); -assertType(shardClientUtil.broadcastEval(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { - return [2 /*return*/, 1]; -}); }); })); -// Test whether the structures implement send -assertType(dmChannel.send); -assertType(threadChannel); -assertType(newsChannel); -assertType(textChannel); -assertType(user); -assertType(guildMember); -assertType(dmChannel.lastMessage); -assertType(threadChannel.lastMessage); -assertType(newsChannel.lastMessage); -assertType(textChannel.lastMessage); -notPropertyOf(user, 'lastMessage'); -notPropertyOf(user, 'lastMessageId'); -notPropertyOf(guildMember, 'lastMessage'); -notPropertyOf(guildMember, 'lastMessageId'); -messageCollector.on('collect', function () { - var args = []; - for (var _i = 0; _i < arguments.length; _i++) { - args[_i] = arguments[_i]; - } - assertType(args); -}); -reactionCollector.on('dispose', function () { - var args = []; - for (var _i = 0; _i < arguments.length; _i++) { - args[_i] = arguments[_i]; - } - assertType(args); -}); -// Make sure the properties are typed correctly, and that no backwards properties -// (K -> V and V -> K) exist: -assertType(_1.Constants.Events.MESSAGE_CREATE); -assertType(_1.Constants.ShardEvents.CLOSE); -assertType(_1.Constants.Status.CONNECTING); -assertType(_1.Constants.Opcodes.DISPATCH); -assertType(_1.Constants.ClientApplicationAssetTypes.BIG); -{ - assertType(applicationCommandManager.create(applicationCommandData)); - assertType(applicationCommandManager.create(applicationCommandData, '0')); - assertType(applicationCommandManager.edit(applicationCommandResolvable, applicationCommandData)); - assertType(applicationCommandManager.edit(applicationCommandResolvable, applicationCommandData, '0')); - assertType(applicationCommandManager.set([applicationCommandData])); - assertType(applicationCommandManager.set([applicationCommandData], '0')); -} -{ - // Options aren't allowed on this command type. - // @ts-expect-error - applicationNonChoiceOptionData.choices; -} -{ - // Choices should be available. - applicationChoiceOptionData.choices; -} -{ - assertType(applicationSubGroupCommandData.type); - assertType(applicationSubGroupCommandData.options); -} -{ - assertType(applicationSubCommandData.type); - // Check that only subcommands can have no subcommand or subcommand group sub-options. - assertType(applicationSubCommandData.options); -} -assertType(guildApplicationCommandManager.fetch()); -assertType(guildApplicationCommandManager.fetch(undefined, {})); -assertType(guildApplicationCommandManager.fetch('0')); -{ - assertType(guildChannelManager.create('name', { type: 'GUILD_VOICE' })); - assertType(guildChannelManager.create('name', { type: 'GUILD_CATEGORY' })); - assertType(guildChannelManager.create('name', { type: 'GUILD_TEXT' })); - assertType(guildChannelManager.create('name', { type: 'GUILD_NEWS' })); - assertType(guildChannelManager.create('name', { type: 'GUILD_STORE' })); - assertType(guildChannelManager.create('name', { type: 'GUILD_STAGE_VOICE' })); - assertType(guildChannelManager.fetch()); - assertType(guildChannelManager.fetch(undefined, {})); - assertType(guildChannelManager.fetch('0')); -} -assertType(roleManager.fetch()); -assertType(roleManager.fetch(undefined, {})); -assertType(roleManager.fetch('0')); -assertType(guildEmojiManager.fetch()); -assertType(guildEmojiManager.fetch(undefined, {})); -assertType(guildEmojiManager.fetch('0')); -assertType(typing.user); -if (typing.user.partial) - assertType(typing.user.username); -assertType(typing.channel); -if (typing.channel.partial) - assertType(typing.channel.lastMessageId); -assertType(typing.member); -assertType(typing.guild); -if (typing.inGuild()) { - assertType(typing.channel.guild); - assertType(typing.guild); -} -// Test partials structures -client.on('guildMemberRemove', function (member) { - if (member.partial) - return assertType(member.joinedAt); - assertType(member.joinedAt); -}); -client.on('messageReactionAdd', function (reaction) { return __awaiter(void 0, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (!reaction.partial) return [3 /*break*/, 2]; - assertType(reaction.count); - return [4 /*yield*/, reaction.fetch()]; - case 1: - reaction = _a.sent(); - _a.label = 2; - case 2: - assertType(reaction.count); - if (reaction.message.partial) - return [2 /*return*/, assertType(reaction.message.content)]; - assertType(reaction.message.content); - return [2 /*return*/]; - } - }); -}); }); -if (interaction.inGuild()) - assertType(interaction.guildId); -client.on('interactionCreate', function (interaction) { return __awaiter(void 0, void 0, void 0, function () { - var msg, btn, optionalOption, requiredOption; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (interaction.inCachedGuild()) { - assertType(interaction.member); - // @ts-expect-error - assertType(interaction); - assertType(interaction); - } - else if (interaction.inRawGuild()) { - assertType(interaction.member); - // @ts-expect-error - consumeCachedInteraction(interaction); - } - else { - assertType(interaction.member); - // @ts-expect-error - consumeCachedInteraction(interaction); - } - if (interaction.isContextMenu()) { - assertType(interaction); - if (interaction.inCachedGuild()) { - assertType(interaction); - assertType(interaction.guild); - assertType(interaction); - } - else if (interaction.inRawGuild()) { - assertType(interaction); - assertType(interaction.guild); - } - else if (interaction.inGuild()) { - assertType(interaction); - assertType(interaction.guild); - } - } - if (interaction.isButton()) { - assertType(interaction); - if (interaction.inCachedGuild()) { - assertType(interaction); - assertType(interaction.guild); - assertType(interaction.reply({ fetchReply: true })); - } - else if (interaction.inRawGuild()) { - assertType(interaction); - assertType(interaction.guild); - assertType(interaction.reply({ fetchReply: true })); - } - else if (interaction.inGuild()) { - assertType(interaction); - assertType(interaction.guild); - assertType(interaction.reply({ fetchReply: true })); - } - } - if (interaction.isMessageComponent()) { - assertType(interaction); - if (interaction.inCachedGuild()) { - assertType(interaction); - assertType(interaction.guild); - assertType(interaction.reply({ fetchReply: true })); - } - else if (interaction.inRawGuild()) { - assertType(interaction); - assertType(interaction.guild); - assertType(interaction.reply({ fetchReply: true })); - } - else if (interaction.inGuild()) { - assertType(interaction); - assertType(interaction.guild); - assertType(interaction.reply({ fetchReply: true })); - } - } - if (interaction.isSelectMenu()) { - assertType(interaction); - if (interaction.inCachedGuild()) { - assertType(interaction); - assertType(interaction.guild); - assertType(interaction.reply({ fetchReply: true })); - } - else if (interaction.inRawGuild()) { - assertType(interaction); - assertType(interaction.guild); - assertType(interaction.reply({ fetchReply: true })); - } - else if (interaction.inGuild()) { - assertType(interaction); - assertType(interaction.guild); - assertType(interaction.reply({ fetchReply: true })); - } - } - if (!interaction.isCommand()) return [3 /*break*/, 6]; - if (!interaction.inRawGuild()) return [3 /*break*/, 1]; - // @ts-expect-error - consumeCachedCommand(interaction); - assertType(interaction); - assertType(interaction.reply({ fetchReply: true })); - assertType(interaction.options.getMember('test')); - assertType(interaction.options.getMember('test', true)); - assertType(interaction.options.getChannel('test', true)); - assertType(interaction.options.getRole('test', true)); - assertType(interaction.options.getMessage('test', true)); - return [3 /*break*/, 5]; - case 1: - if (!interaction.inCachedGuild()) return [3 /*break*/, 4]; - return [4 /*yield*/, interaction.reply({ fetchReply: true })]; - case 2: - msg = _a.sent(); - return [4 /*yield*/, msg.awaitMessageComponent({ componentType: 'BUTTON' })]; - case 3: - btn = _a.sent(); - assertType(msg); - assertType(btn); - assertType(interaction); - assertType(interaction.options.getMember('test', true)); - assertType(interaction.options.getMember('test')); - assertType(interaction); - assertType(interaction.reply({ fetchReply: true })); - assertType(interaction.options.getChannel('test', true)); - assertType(interaction.options.getRole('test', true)); - assertType(interaction.options.getMessage('test', true)); - return [3 /*break*/, 5]; - case 4: - // @ts-expect-error - consumeCachedCommand(interaction); - assertType(interaction); - assertType(interaction.reply({ fetchReply: true })); - assertType(interaction.options.getMember('test')); - assertType(interaction.options.getMember('test', true)); - assertType(interaction.options.getChannel('test', true)); - assertType(interaction.options.getRole('test', true)); - assertType(interaction.options.getMessage('test', true)); - _a.label = 5; - case 5: - assertType(interaction); - assertType(interaction.options); - assertType(interaction.options.data); - optionalOption = interaction.options.get('name'); - requiredOption = interaction.options.get('name', true); - assertType(optionalOption); - assertType(requiredOption); - assertType(requiredOption.options); - assertType(interaction.options.getString('name', booleanValue)); - assertType(interaction.options.getString('name', false)); - assertType(interaction.options.getString('name', true)); - assertType(interaction.options.getSubcommand()); - assertType(interaction.options.getSubcommand(true)); - assertType(interaction.options.getSubcommand(booleanValue)); - assertType(interaction.options.getSubcommand(false)); - assertType(interaction.options.getSubcommandGroup()); - assertType(interaction.options.getSubcommandGroup(true)); - assertType(interaction.options.getSubcommandGroup(booleanValue)); - assertType(interaction.options.getSubcommandGroup(false)); - _a.label = 6; - case 6: return [2 /*return*/]; - } - }); -}); });