fix(ApplicationCommand): use new ApplicationCommandOptionType enums (#7257)

This commit is contained in:
Koyamie
2022-01-14 00:20:45 +01:00
committed by GitHub
parent f284a4641f
commit 06f5210f58
4 changed files with 15 additions and 14 deletions

View File

@@ -1,7 +1,8 @@
'use strict'; 'use strict';
const { ComponentType } = require('discord-api-types/v9');
const { TypeError } = require('../errors'); const { TypeError } = require('../errors');
const { MessageComponentTypes, Events } = require('../util/Constants'); const { Events } = require('../util/Constants');
/** /**
* Represents an interactive component of a Message. It should not be necessary to construct this directly. * Represents an interactive component of a Message. It should not be necessary to construct this directly.
@@ -61,20 +62,20 @@ class BaseMessageComponent {
let component; let component;
let type = data.type; let type = data.type;
if (typeof type === 'string') type = MessageComponentTypes[type]; if (typeof type === 'string') type = ComponentType[type];
switch (type) { switch (type) {
case MessageComponentTypes.ACTION_ROW: { case ComponentType.ActionRow: {
const MessageActionRow = require('./MessageActionRow'); const MessageActionRow = require('./MessageActionRow');
component = data instanceof MessageActionRow ? data : new MessageActionRow(data, client); component = data instanceof MessageActionRow ? data : new MessageActionRow(data, client);
break; break;
} }
case MessageComponentTypes.BUTTON: { case ComponentType.Button: {
const MessageButton = require('./MessageButton'); const MessageButton = require('./MessageButton');
component = data instanceof MessageButton ? data : new MessageButton(data); component = data instanceof MessageButton ? data : new MessageButton(data);
break; break;
} }
case MessageComponentTypes.SELECT_MENU: { case ComponentType.SelectMenu: {
const MessageSelectMenu = require('./MessageSelectMenu'); const MessageSelectMenu = require('./MessageSelectMenu');
component = data instanceof MessageSelectMenu ? data : new MessageSelectMenu(data); component = data instanceof MessageSelectMenu ? data : new MessageSelectMenu(data);
break; break;
@@ -96,7 +97,7 @@ class BaseMessageComponent {
* @private * @private
*/ */
static resolveType(type) { static resolveType(type) {
return typeof type === 'string' ? type : MessageComponentTypes[type]; return typeof type === 'string' ? type : ComponentType[type];
} }
} }

View File

@@ -1,7 +1,7 @@
'use strict'; 'use strict';
const { ComponentType } = require('discord-api-types/v9');
const BaseMessageComponent = require('./BaseMessageComponent'); const BaseMessageComponent = require('./BaseMessageComponent');
const { MessageComponentTypes } = require('../util/Constants');
/** /**
* Represents an action row containing message components. * Represents an action row containing message components.
@@ -88,7 +88,7 @@ class MessageActionRow extends BaseMessageComponent {
toJSON() { toJSON() {
return { return {
components: this.components.map(c => c.toJSON()), components: this.components.map(c => c.toJSON()),
type: MessageComponentTypes[this.type], type: ComponentType[this.type],
}; };
} }
} }

View File

@@ -1,8 +1,8 @@
'use strict'; 'use strict';
const { ButtonStyle, ComponentType } = require('discord-api-types/v9');
const BaseMessageComponent = require('./BaseMessageComponent'); const BaseMessageComponent = require('./BaseMessageComponent');
const { RangeError } = require('../errors'); const { RangeError } = require('../errors');
const { MessageButtonStyles, MessageComponentTypes } = require('../util/Constants');
const Util = require('../util/Util'); const Util = require('../util/Util');
/** /**
@@ -138,8 +138,8 @@ class MessageButton extends BaseMessageComponent {
disabled: this.disabled, disabled: this.disabled,
emoji: this.emoji, emoji: this.emoji,
label: this.label, label: this.label,
style: MessageButtonStyles[this.style], style: ButtonStyle[this.style],
type: MessageComponentTypes[this.type], type: ComponentType[this.type],
url: this.url, url: this.url,
}; };
} }
@@ -158,7 +158,7 @@ class MessageButton extends BaseMessageComponent {
* @private * @private
*/ */
static resolveStyle(style) { static resolveStyle(style) {
return typeof style === 'string' ? style : MessageButtonStyles[style]; return typeof style === 'string' ? style : ButtonStyle[style];
} }
} }

View File

@@ -1,7 +1,7 @@
'use strict'; 'use strict';
const { ComponentType } = require('discord-api-types/v9');
const BaseMessageComponent = require('./BaseMessageComponent'); const BaseMessageComponent = require('./BaseMessageComponent');
const { MessageComponentTypes } = require('../util/Constants');
const Util = require('../util/Util'); const Util = require('../util/Util');
/** /**
@@ -179,7 +179,7 @@ class MessageSelectMenu extends BaseMessageComponent {
min_values: this.minValues, min_values: this.minValues,
max_values: this.maxValues ?? (this.minValues ? this.options.length : undefined), max_values: this.maxValues ?? (this.minValues ? this.options.length : undefined),
options: this.options, options: this.options,
type: typeof this.type === 'string' ? MessageComponentTypes[this.type] : this.type, type: typeof this.type === 'string' ? ComponentType[this.type] : this.type,
}; };
} }