fix: sendSlash in dm channel
This commit is contained in:
parent
a768fbf590
commit
0975224da0
File diff suppressed because one or more lines are too long
@ -47,11 +47,11 @@ class InteractionCreateAction extends Action {
|
|||||||
case MessageComponentTypes.BUTTON:
|
case MessageComponentTypes.BUTTON:
|
||||||
InteractionType = ButtonInteraction;
|
InteractionType = ButtonInteraction;
|
||||||
break;
|
break;
|
||||||
case MessageComponentTypes.STRING_SELECT_MENU:
|
case MessageComponentTypes.STRING_SELECT:
|
||||||
case MessageComponentTypes.USER_SELECT_MENU:
|
case MessageComponentTypes.USER_SELECT:
|
||||||
case MessageComponentTypes.ROLE_SELECT_MENU:
|
case MessageComponentTypes.ROLE_SELECT:
|
||||||
case MessageComponentTypes.MENTIONABLE_SELECT_MENU:
|
case MessageComponentTypes.MENTIONABLE_SELECT:
|
||||||
case MessageComponentTypes.CHANNEL_SELECT_MENU:
|
case MessageComponentTypes.CHANNEL_SELECT:
|
||||||
InteractionType = SelectMenuInteraction;
|
InteractionType = SelectMenuInteraction;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -32,7 +32,7 @@ async function checkUpdate(client) {
|
|||||||
|
|
||||||
If you don't want to show this message, set ${chalk.cyanBright('checkUpdate')} to false
|
If you don't want to show this message, set ${chalk.cyanBright('checkUpdate')} to false
|
||||||
|
|
||||||
new Client({
|
const client = new Client({
|
||||||
checkUpdate: false,
|
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
|
If you don't want to show this message, set ${chalk.cyanBright('checkUpdate')} to false
|
||||||
|
|
||||||
new Client({
|
const client = new Client({
|
||||||
checkUpdate: false,
|
checkUpdate: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -76,11 +76,11 @@ class BaseMessageComponent {
|
|||||||
component = data instanceof MessageButton ? data : new MessageButton(data);
|
component = data instanceof MessageButton ? data : new MessageButton(data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MessageComponentTypes.STRING_SELECT_MENU:
|
case MessageComponentTypes.STRING_SELECT:
|
||||||
case MessageComponentTypes.USER_SELECT_MENU:
|
case MessageComponentTypes.USER_SELECT:
|
||||||
case MessageComponentTypes.ROLE_SELECT_MENU:
|
case MessageComponentTypes.ROLE_SELECT:
|
||||||
case MessageComponentTypes.MENTIONABLE_SELECT_MENU:
|
case MessageComponentTypes.MENTIONABLE_SELECT:
|
||||||
case MessageComponentTypes.CHANNEL_SELECT_MENU: {
|
case MessageComponentTypes.CHANNEL_SELECT: {
|
||||||
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;
|
||||||
|
@ -1075,11 +1075,11 @@ class Message extends Base {
|
|||||||
for (const component of row.components) {
|
for (const component of row.components) {
|
||||||
if (
|
if (
|
||||||
[
|
[
|
||||||
'STRING_SELECT_MENU',
|
'STRING_SELECT',
|
||||||
'USER_SELECT_MENU',
|
'USER_SELECT',
|
||||||
'ROLE_SELECT_MENU',
|
'ROLE_SELECT',
|
||||||
'MENTIONABLE_SELECT_MENU',
|
'MENTIONABLE_SELECT',
|
||||||
'CHANNEL_SELECT_MENU',
|
'CHANNEL_SELECT',
|
||||||
].includes(component.type)
|
].includes(component.type)
|
||||||
) {
|
) {
|
||||||
menuAll.push(component);
|
menuAll.push(component);
|
||||||
|
@ -44,7 +44,7 @@ class MessageSelectMenu extends BaseMessageComponent {
|
|||||||
* @param {MessageSelectMenu|MessageSelectMenuOptions} [data={}] MessageSelectMenu to clone or raw data
|
* @param {MessageSelectMenu|MessageSelectMenuOptions} [data={}] MessageSelectMenu to clone or raw data
|
||||||
*/
|
*/
|
||||||
constructor(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);
|
this.setup(data);
|
||||||
}
|
}
|
||||||
@ -90,11 +90,11 @@ class MessageSelectMenu extends BaseMessageComponent {
|
|||||||
/**
|
/**
|
||||||
* @typedef {string} SelectMenuTypes
|
* @typedef {string} SelectMenuTypes
|
||||||
* Must be one of:
|
* Must be one of:
|
||||||
* * `STRING_SELECT_MENU`
|
* * `STRING_SELECT`
|
||||||
* * `USER_SELECT_MENU`
|
* * `USER_SELECT`
|
||||||
* * `ROLE_SELECT_MENU`
|
* * `ROLE_SELECT`
|
||||||
* * `MENTIONABLE_SELECT_MENU`
|
* * `MENTIONABLE_SELECT`
|
||||||
* * `CHANNEL_SELECT_MENU`
|
* * `CHANNEL_SELECT`
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -104,7 +104,7 @@ class MessageSelectMenu extends BaseMessageComponent {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
setType(type) {
|
setType(type) {
|
||||||
if (!type) type = MessageComponentTypes.STRING_SELECT_MENU;
|
if (!type) type = MessageComponentTypes.STRING_SELECT;
|
||||||
this.type = MessageSelectMenu.resolveType(type);
|
this.type = MessageSelectMenu.resolveType(type);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -260,28 +260,28 @@ class MessageSelectMenu extends BaseMessageComponent {
|
|||||||
});
|
});
|
||||||
const parseValues = value => {
|
const parseValues = value => {
|
||||||
switch (this.type) {
|
switch (this.type) {
|
||||||
case 'STRING_SELECT_MENU': {
|
case 'STRING_SELECT': {
|
||||||
if (typeof value !== 'string') throw new TypeError('[INVALID_VALUE] Please pass a string value');
|
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);
|
const value_ = this.options.find(obj => obj.value === value || obj.label === value);
|
||||||
if (!value_) throw new Error('[INVALID_VALUE] Please pass a valid value');
|
if (!value_) throw new Error('[INVALID_VALUE] Please pass a valid value');
|
||||||
return value_.value;
|
return value_.value;
|
||||||
}
|
}
|
||||||
case 'USER_SELECT_MENU': {
|
case 'USER_SELECT': {
|
||||||
const userId = this.client.users.resolveId(value);
|
const userId = this.client.users.resolveId(value);
|
||||||
if (!userId) throw new Error('[INVALID_VALUE] Please pass a valid user');
|
if (!userId) throw new Error('[INVALID_VALUE] Please pass a valid user');
|
||||||
return userId;
|
return userId;
|
||||||
}
|
}
|
||||||
case 'ROLE_SELECT_MENU': {
|
case 'ROLE_SELECT': {
|
||||||
const roleId = this.client.roles.resolveId(value);
|
const roleId = this.client.roles.resolveId(value);
|
||||||
if (!roleId) throw new Error('[INVALID_VALUE] Please pass a valid role');
|
if (!roleId) throw new Error('[INVALID_VALUE] Please pass a valid role');
|
||||||
return roleId;
|
return roleId;
|
||||||
}
|
}
|
||||||
case 'MENTIONABLE_SELECT_MENU': {
|
case 'MENTIONABLE_SELECT': {
|
||||||
const mentionableId = this.client.users.resolveId(value) || this.client.roles.resolveId(value);
|
const mentionableId = this.client.users.resolveId(value) || this.client.roles.resolveId(value);
|
||||||
if (!mentionableId) throw new Error('[INVALID_VALUE] Please pass a valid mentionable');
|
if (!mentionableId) throw new Error('[INVALID_VALUE] Please pass a valid mentionable');
|
||||||
return mentionableId;
|
return mentionableId;
|
||||||
}
|
}
|
||||||
case 'CHANNEL_SELECT_MENU': {
|
case 'CHANNEL_SELECT': {
|
||||||
const channelId = this.client.channels.resolveId(value);
|
const channelId = this.client.channels.resolveId(value);
|
||||||
if (!channelId) throw new Error('[INVALID_VALUE] Please pass a valid channel');
|
if (!channelId) throw new Error('[INVALID_VALUE] Please pass a valid channel');
|
||||||
return channelId;
|
return channelId;
|
||||||
|
@ -454,14 +454,19 @@ class TextBasedChannel {
|
|||||||
* channel.sendSlash('123456789012345678', 'embed title', 'description', 'author', '#00ff00')
|
* channel.sendSlash('123456789012345678', 'embed title', 'description', 'author', '#00ff00')
|
||||||
*/
|
*/
|
||||||
async sendSlash(bot, commandString, ...args) {
|
async sendSlash(bot, commandString, ...args) {
|
||||||
const perms = this.permissionsFor(this.client.user);
|
const perms =
|
||||||
if (!perms.has('SEND_MESSAGES')) {
|
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(
|
throw new Error(
|
||||||
'INTERACTION_SEND_FAILURE',
|
'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(
|
throw new Error(
|
||||||
'INTERACTION_SEND_FAILURE',
|
'INTERACTION_SEND_FAILURE',
|
||||||
`Cannot send Slash to ${this.toString()} due to missing USE_APPLICATION_COMMANDS permission`,
|
`Cannot send Slash to ${this.toString()} due to missing USE_APPLICATION_COMMANDS permission`,
|
||||||
|
@ -1513,12 +1513,12 @@ exports.InteractionResponseTypes = createEnum([
|
|||||||
* The type of a message component
|
* The type of a message component
|
||||||
* * ACTION_ROW
|
* * ACTION_ROW
|
||||||
* * BUTTON
|
* * BUTTON
|
||||||
* * STRING_SELECT_MENU
|
* * STRING_SELECT
|
||||||
* * TEXT_INPUT
|
* * TEXT_INPUT
|
||||||
* * USER_SELECT_MENU
|
* * USER_SELECT
|
||||||
* * ROLE_SELECT_MENU
|
* * ROLE_SELECT
|
||||||
* * MENTIONABLE_SELECT_MENU
|
* * MENTIONABLE_SELECT
|
||||||
* * CHANNEL_SELECT_MENU
|
* * CHANNEL_SELECT
|
||||||
* @typedef {string} MessageComponentType
|
* @typedef {string} MessageComponentType
|
||||||
* @see {@link https://discord.com/developers/docs/interactions/message-components#component-object-component-types}
|
* @see {@link https://discord.com/developers/docs/interactions/message-components#component-object-component-types}
|
||||||
*/
|
*/
|
||||||
@ -1526,12 +1526,12 @@ exports.MessageComponentTypes = createEnum([
|
|||||||
null,
|
null,
|
||||||
'ACTION_ROW',
|
'ACTION_ROW',
|
||||||
'BUTTON',
|
'BUTTON',
|
||||||
'STRING_SELECT_MENU',
|
'STRING_SELECT',
|
||||||
'TEXT_INPUT',
|
'TEXT_INPUT',
|
||||||
'USER_SELECT_MENU',
|
'USER_SELECT',
|
||||||
'ROLE_SELECT_MENU',
|
'ROLE_SELECT',
|
||||||
'MENTIONABLE_SELECT_MENU',
|
'MENTIONABLE_SELECT',
|
||||||
'CHANNEL_SELECT_MENU',
|
'CHANNEL_SELECT',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
10
typings/enums.d.ts
vendored
10
typings/enums.d.ts
vendored
@ -218,12 +218,12 @@ export const enum MessageButtonStyles {
|
|||||||
export const enum MessageComponentTypes {
|
export const enum MessageComponentTypes {
|
||||||
ACTION_ROW = 1,
|
ACTION_ROW = 1,
|
||||||
BUTTON = 2,
|
BUTTON = 2,
|
||||||
STRING_SELECT_MENU = 3,
|
STRING_SELECT = 3,
|
||||||
TEXT_INPUT = 4,
|
TEXT_INPUT = 4,
|
||||||
USER_SELECT_MENU = 5,
|
USER_SELECT = 5,
|
||||||
ROLE_SELECT_MENU = 6,
|
ROLE_SELECT = 6,
|
||||||
MENTIONABLE_SELECT_MENU = 7,
|
MENTIONABLE_SELECT = 7,
|
||||||
CHANNEL_SELECT_MENU = 8,
|
CHANNEL_SELECT = 8,
|
||||||
}
|
}
|
||||||
|
|
||||||
export const enum ModalComponentTypes {
|
export const enum ModalComponentTypes {
|
||||||
|
30
typings/index.d.ts
vendored
30
typings/index.d.ts
vendored
@ -1863,12 +1863,12 @@ export type AwaitMessageCollectorOptionsParams<
|
|||||||
|
|
||||||
export interface StringMappedInteractionTypes<Cached extends CacheType = CacheType> {
|
export interface StringMappedInteractionTypes<Cached extends CacheType = CacheType> {
|
||||||
BUTTON: ButtonInteraction<Cached>;
|
BUTTON: ButtonInteraction<Cached>;
|
||||||
STRING_SELECT_MENU: SelectMenuInteraction<Cached>;
|
STRING_SELECT: SelectMenuInteraction<Cached>;
|
||||||
ACTION_ROW: MessageComponentInteraction<Cached>;
|
ACTION_ROW: MessageComponentInteraction<Cached>;
|
||||||
USER_SELECT_MENU: SelectMenuInteraction<Cached>;
|
USER_SELECT: SelectMenuInteraction<Cached>;
|
||||||
ROLE_SELECT_MENU: SelectMenuInteraction<Cached>;
|
ROLE_SELECT: SelectMenuInteraction<Cached>;
|
||||||
MENTIONABLE_SELECT_MENU: SelectMenuInteraction<Cached>;
|
MENTIONABLE_SELECT: SelectMenuInteraction<Cached>;
|
||||||
CHANNEL_SELECT_MENU: SelectMenuInteraction<Cached>;
|
CHANNEL_SELECT: SelectMenuInteraction<Cached>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type WrapBooleanCache<T extends boolean> = If<T, 'cached', CacheType>;
|
export type WrapBooleanCache<T extends boolean> = If<T, 'cached', CacheType>;
|
||||||
@ -1877,13 +1877,13 @@ export type MappedInteractionTypes<Cached extends boolean = boolean> = EnumValue
|
|||||||
typeof MessageComponentTypes,
|
typeof MessageComponentTypes,
|
||||||
{
|
{
|
||||||
BUTTON: ButtonInteraction<WrapBooleanCache<Cached>>;
|
BUTTON: ButtonInteraction<WrapBooleanCache<Cached>>;
|
||||||
STRING_SELECT_MENU: SelectMenuInteraction<WrapBooleanCache<Cached>>;
|
STRING_SELECT: SelectMenuInteraction<WrapBooleanCache<Cached>>;
|
||||||
ACTION_ROW: MessageComponentInteraction<WrapBooleanCache<Cached>>;
|
ACTION_ROW: MessageComponentInteraction<WrapBooleanCache<Cached>>;
|
||||||
TEXT_INPUT: ModalSubmitInteraction<WrapBooleanCache<Cached>>;
|
TEXT_INPUT: ModalSubmitInteraction<WrapBooleanCache<Cached>>;
|
||||||
USER_SELECT_MENU: SelectMenuInteraction<WrapBooleanCache<Cached>>;
|
USER_SELECT: SelectMenuInteraction<WrapBooleanCache<Cached>>;
|
||||||
ROLE_SELECT_MENU: SelectMenuInteraction<WrapBooleanCache<Cached>>;
|
ROLE_SELECT: SelectMenuInteraction<WrapBooleanCache<Cached>>;
|
||||||
MENTIONABLE_SELECT_MENU: SelectMenuInteraction<WrapBooleanCache<Cached>>;
|
MENTIONABLE_SELECT: SelectMenuInteraction<WrapBooleanCache<Cached>>;
|
||||||
CHANNEL_SELECT_MENU: SelectMenuInteraction<WrapBooleanCache<Cached>>;
|
CHANNEL_SELECT: SelectMenuInteraction<WrapBooleanCache<Cached>>;
|
||||||
}
|
}
|
||||||
>;
|
>;
|
||||||
|
|
||||||
@ -2554,11 +2554,11 @@ export class Role extends Base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type SelectMenuTypes =
|
export type SelectMenuTypes =
|
||||||
| 'STRING_SELECT_MENU'
|
| 'STRING_SELECT'
|
||||||
| 'USER_SELECT_MENU'
|
| 'USER_SELECT'
|
||||||
| 'ROLE_SELECT_MENU'
|
| 'ROLE_SELECT'
|
||||||
| 'MENTIONABLE_SELECT_MENU'
|
| 'MENTIONABLE_SELECT'
|
||||||
| 'CHANNEL_SELECT_MENU';
|
| 'CHANNEL_SELECT';
|
||||||
|
|
||||||
export class SelectMenuInteraction<Cached extends CacheType = CacheType> extends MessageComponentInteraction<Cached> {
|
export class SelectMenuInteraction<Cached extends CacheType = CacheType> extends MessageComponentInteraction<Cached> {
|
||||||
public constructor(client: Client, data: RawMessageSelectMenuInteractionData);
|
public constructor(client: Client, data: RawMessageSelectMenuInteractionData);
|
||||||
|
Loading…
Reference in New Issue
Block a user