fix: sendSlash in dm channel

This commit is contained in:
March 7th 2022-11-06 12:05:18 +07:00
parent a768fbf590
commit 0975224da0
10 changed files with 69 additions and 64 deletions

File diff suppressed because one or more lines are too long

View File

@ -47,11 +47,11 @@ class InteractionCreateAction extends Action {
case MessageComponentTypes.BUTTON:
InteractionType = ButtonInteraction;
break;
case MessageComponentTypes.STRING_SELECT_MENU:
case MessageComponentTypes.USER_SELECT_MENU:
case MessageComponentTypes.ROLE_SELECT_MENU:
case MessageComponentTypes.MENTIONABLE_SELECT_MENU:
case MessageComponentTypes.CHANNEL_SELECT_MENU:
case MessageComponentTypes.STRING_SELECT:
case MessageComponentTypes.USER_SELECT:
case MessageComponentTypes.ROLE_SELECT:
case MessageComponentTypes.MENTIONABLE_SELECT:
case MessageComponentTypes.CHANNEL_SELECT:
InteractionType = SelectMenuInteraction;
break;
default:

View File

@ -32,7 +32,7 @@ async function checkUpdate(client) {
If you don't want to show this message, set ${chalk.cyanBright('checkUpdate')} to false
new Client({
const client = new Client({
checkUpdate: false,
});
@ -46,7 +46,7 @@ async function checkUpdate(client) {
If you don't want to show this message, set ${chalk.cyanBright('checkUpdate')} to false
new Client({
const client = new Client({
checkUpdate: false,
});

View File

@ -76,11 +76,11 @@ class BaseMessageComponent {
component = data instanceof MessageButton ? data : new MessageButton(data);
break;
}
case MessageComponentTypes.STRING_SELECT_MENU:
case MessageComponentTypes.USER_SELECT_MENU:
case MessageComponentTypes.ROLE_SELECT_MENU:
case MessageComponentTypes.MENTIONABLE_SELECT_MENU:
case MessageComponentTypes.CHANNEL_SELECT_MENU: {
case MessageComponentTypes.STRING_SELECT:
case MessageComponentTypes.USER_SELECT:
case MessageComponentTypes.ROLE_SELECT:
case MessageComponentTypes.MENTIONABLE_SELECT:
case MessageComponentTypes.CHANNEL_SELECT: {
const MessageSelectMenu = require('./MessageSelectMenu');
component = data instanceof MessageSelectMenu ? data : new MessageSelectMenu(data);
break;

View File

@ -1075,11 +1075,11 @@ class Message extends Base {
for (const component of row.components) {
if (
[
'STRING_SELECT_MENU',
'USER_SELECT_MENU',
'ROLE_SELECT_MENU',
'MENTIONABLE_SELECT_MENU',
'CHANNEL_SELECT_MENU',
'STRING_SELECT',
'USER_SELECT',
'ROLE_SELECT',
'MENTIONABLE_SELECT',
'CHANNEL_SELECT',
].includes(component.type)
) {
menuAll.push(component);

View File

@ -44,7 +44,7 @@ class MessageSelectMenu extends BaseMessageComponent {
* @param {MessageSelectMenu|MessageSelectMenuOptions} [data={}] MessageSelectMenu to clone or raw data
*/
constructor(data = {}) {
super({ type: data?.type ? MessageComponentTypes[data.type] : 'STRING_SELECT_MENU' });
super({ type: data?.type ? MessageComponentTypes[data.type] : 'STRING_SELECT' });
this.setup(data);
}
@ -90,11 +90,11 @@ class MessageSelectMenu extends BaseMessageComponent {
/**
* @typedef {string} SelectMenuTypes
* Must be one of:
* * `STRING_SELECT_MENU`
* * `USER_SELECT_MENU`
* * `ROLE_SELECT_MENU`
* * `MENTIONABLE_SELECT_MENU`
* * `CHANNEL_SELECT_MENU`
* * `STRING_SELECT`
* * `USER_SELECT`
* * `ROLE_SELECT`
* * `MENTIONABLE_SELECT`
* * `CHANNEL_SELECT`
*/
/**
@ -104,7 +104,7 @@ class MessageSelectMenu extends BaseMessageComponent {
*/
setType(type) {
if (!type) type = MessageComponentTypes.STRING_SELECT_MENU;
if (!type) type = MessageComponentTypes.STRING_SELECT;
this.type = MessageSelectMenu.resolveType(type);
return this;
}
@ -260,28 +260,28 @@ class MessageSelectMenu extends BaseMessageComponent {
});
const parseValues = value => {
switch (this.type) {
case 'STRING_SELECT_MENU': {
case 'STRING_SELECT': {
if (typeof value !== 'string') throw new TypeError('[INVALID_VALUE] Please pass a string value');
const value_ = this.options.find(obj => obj.value === value || obj.label === value);
if (!value_) throw new Error('[INVALID_VALUE] Please pass a valid value');
return value_.value;
}
case 'USER_SELECT_MENU': {
case 'USER_SELECT': {
const userId = this.client.users.resolveId(value);
if (!userId) throw new Error('[INVALID_VALUE] Please pass a valid user');
return userId;
}
case 'ROLE_SELECT_MENU': {
case 'ROLE_SELECT': {
const roleId = this.client.roles.resolveId(value);
if (!roleId) throw new Error('[INVALID_VALUE] Please pass a valid role');
return roleId;
}
case 'MENTIONABLE_SELECT_MENU': {
case 'MENTIONABLE_SELECT': {
const mentionableId = this.client.users.resolveId(value) || this.client.roles.resolveId(value);
if (!mentionableId) throw new Error('[INVALID_VALUE] Please pass a valid mentionable');
return mentionableId;
}
case 'CHANNEL_SELECT_MENU': {
case 'CHANNEL_SELECT': {
const channelId = this.client.channels.resolveId(value);
if (!channelId) throw new Error('[INVALID_VALUE] Please pass a valid channel');
return channelId;

View File

@ -454,14 +454,19 @@ class TextBasedChannel {
* channel.sendSlash('123456789012345678', 'embed title', 'description', 'author', '#00ff00')
*/
async sendSlash(bot, commandString, ...args) {
const perms = this.permissionsFor(this.client.user);
if (!perms.has('SEND_MESSAGES')) {
const perms =
this.type != 'DM'
? this.permissionsFor(this.client.user).toArray()
: ['USE_APPLICATION_COMMANDS', `${this.recipient.relationships == 'BLOCKED' ? '' : 'SEND_MESSAGES'}`];
if (!perms.includes('SEND_MESSAGES')) {
throw new Error(
'INTERACTION_SEND_FAILURE',
`Cannot send Slash to ${this.toString()} due to missing SEND_MESSAGES permission`,
`Cannot send Slash to ${this.toString()} ${
this.recipient ? 'because user has been blocked' : 'due to missing SEND_MESSAGES permission'
}`,
);
}
if (!perms.has('USE_APPLICATION_COMMANDS')) {
if (!perms.includes('USE_APPLICATION_COMMANDS')) {
throw new Error(
'INTERACTION_SEND_FAILURE',
`Cannot send Slash to ${this.toString()} due to missing USE_APPLICATION_COMMANDS permission`,

View File

@ -1513,12 +1513,12 @@ exports.InteractionResponseTypes = createEnum([
* The type of a message component
* * ACTION_ROW
* * BUTTON
* * STRING_SELECT_MENU
* * STRING_SELECT
* * TEXT_INPUT
* * USER_SELECT_MENU
* * ROLE_SELECT_MENU
* * MENTIONABLE_SELECT_MENU
* * CHANNEL_SELECT_MENU
* * USER_SELECT
* * ROLE_SELECT
* * MENTIONABLE_SELECT
* * CHANNEL_SELECT
* @typedef {string} MessageComponentType
* @see {@link https://discord.com/developers/docs/interactions/message-components#component-object-component-types}
*/
@ -1526,12 +1526,12 @@ exports.MessageComponentTypes = createEnum([
null,
'ACTION_ROW',
'BUTTON',
'STRING_SELECT_MENU',
'STRING_SELECT',
'TEXT_INPUT',
'USER_SELECT_MENU',
'ROLE_SELECT_MENU',
'MENTIONABLE_SELECT_MENU',
'CHANNEL_SELECT_MENU',
'USER_SELECT',
'ROLE_SELECT',
'MENTIONABLE_SELECT',
'CHANNEL_SELECT',
]);
/**

10
typings/enums.d.ts vendored
View File

@ -218,12 +218,12 @@ export const enum MessageButtonStyles {
export const enum MessageComponentTypes {
ACTION_ROW = 1,
BUTTON = 2,
STRING_SELECT_MENU = 3,
STRING_SELECT = 3,
TEXT_INPUT = 4,
USER_SELECT_MENU = 5,
ROLE_SELECT_MENU = 6,
MENTIONABLE_SELECT_MENU = 7,
CHANNEL_SELECT_MENU = 8,
USER_SELECT = 5,
ROLE_SELECT = 6,
MENTIONABLE_SELECT = 7,
CHANNEL_SELECT = 8,
}
export const enum ModalComponentTypes {

30
typings/index.d.ts vendored
View File

@ -1863,12 +1863,12 @@ export type AwaitMessageCollectorOptionsParams<
export interface StringMappedInteractionTypes<Cached extends CacheType = CacheType> {
BUTTON: ButtonInteraction<Cached>;
STRING_SELECT_MENU: SelectMenuInteraction<Cached>;
STRING_SELECT: SelectMenuInteraction<Cached>;
ACTION_ROW: MessageComponentInteraction<Cached>;
USER_SELECT_MENU: SelectMenuInteraction<Cached>;
ROLE_SELECT_MENU: SelectMenuInteraction<Cached>;
MENTIONABLE_SELECT_MENU: SelectMenuInteraction<Cached>;
CHANNEL_SELECT_MENU: SelectMenuInteraction<Cached>;
USER_SELECT: SelectMenuInteraction<Cached>;
ROLE_SELECT: SelectMenuInteraction<Cached>;
MENTIONABLE_SELECT: SelectMenuInteraction<Cached>;
CHANNEL_SELECT: SelectMenuInteraction<Cached>;
}
export type WrapBooleanCache<T extends boolean> = If<T, 'cached', CacheType>;
@ -1877,13 +1877,13 @@ export type MappedInteractionTypes<Cached extends boolean = boolean> = EnumValue
typeof MessageComponentTypes,
{
BUTTON: ButtonInteraction<WrapBooleanCache<Cached>>;
STRING_SELECT_MENU: SelectMenuInteraction<WrapBooleanCache<Cached>>;
STRING_SELECT: SelectMenuInteraction<WrapBooleanCache<Cached>>;
ACTION_ROW: MessageComponentInteraction<WrapBooleanCache<Cached>>;
TEXT_INPUT: ModalSubmitInteraction<WrapBooleanCache<Cached>>;
USER_SELECT_MENU: SelectMenuInteraction<WrapBooleanCache<Cached>>;
ROLE_SELECT_MENU: SelectMenuInteraction<WrapBooleanCache<Cached>>;
MENTIONABLE_SELECT_MENU: SelectMenuInteraction<WrapBooleanCache<Cached>>;
CHANNEL_SELECT_MENU: SelectMenuInteraction<WrapBooleanCache<Cached>>;
USER_SELECT: SelectMenuInteraction<WrapBooleanCache<Cached>>;
ROLE_SELECT: SelectMenuInteraction<WrapBooleanCache<Cached>>;
MENTIONABLE_SELECT: SelectMenuInteraction<WrapBooleanCache<Cached>>;
CHANNEL_SELECT: SelectMenuInteraction<WrapBooleanCache<Cached>>;
}
>;
@ -2554,11 +2554,11 @@ export class Role extends Base {
}
export type SelectMenuTypes =
| 'STRING_SELECT_MENU'
| 'USER_SELECT_MENU'
| 'ROLE_SELECT_MENU'
| 'MENTIONABLE_SELECT_MENU'
| 'CHANNEL_SELECT_MENU';
| 'STRING_SELECT'
| 'USER_SELECT'
| 'ROLE_SELECT'
| 'MENTIONABLE_SELECT'
| 'CHANNEL_SELECT';
export class SelectMenuInteraction<Cached extends CacheType = CacheType> extends MessageComponentInteraction<Cached> {
public constructor(client: Client, data: RawMessageSelectMenuInteractionData);