maybe minor update ?
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const process = require('node:process');
|
||||
const { Message } = require('discord.js');
|
||||
const Base = require('./Base');
|
||||
let CategoryChannel;
|
||||
let DMChannel;
|
||||
@@ -230,51 +229,6 @@ class Channel extends Base {
|
||||
toJSON(...props) {
|
||||
return super.toJSON({ createdTimestamp: true }, ...props);
|
||||
}
|
||||
|
||||
// Send Slash
|
||||
/**
|
||||
* Send Slash to this channel
|
||||
* @param {DiscordBot} botID Bot ID
|
||||
* @param {string<ApplicationCommand.name>} commandName Command name
|
||||
* @param {Array<ApplicationCommand.options>} args Command arguments
|
||||
* @returns {Promise<pending>}
|
||||
*/
|
||||
async sendSlash(botID, commandName, args = []) {
|
||||
if (!this.isText()) throw new Error('This channel is not text-based.');
|
||||
if (!botID) throw new Error('Bot ID is required');
|
||||
const user = await this.client.users.fetch(botID).catch(() => {});
|
||||
if (!user || !user.bot || !user.applications) {
|
||||
throw new Error('BotID is not a bot or does not have an application slash command');
|
||||
}
|
||||
if (!commandName || typeof commandName !== 'string') throw new Error('Command name is required');
|
||||
const listApplication =
|
||||
user.applications.cache.size == 0 ? await user.applications.fetch() : user.applications.cache;
|
||||
let slashCommand;
|
||||
await Promise.all(
|
||||
listApplication.map(application => {
|
||||
if (commandName == application.name && application.type == 'CHAT_INPUT') slashCommand = application;
|
||||
return true;
|
||||
}),
|
||||
);
|
||||
if (!slashCommand) {
|
||||
throw new Error(
|
||||
`Command ${commandName} is not found\nList command avalible: ${listApplication
|
||||
.filter(a => a.type == 'CHAT_INPUT')
|
||||
.map(a => a.name)
|
||||
.join(', ')}`,
|
||||
);
|
||||
}
|
||||
return slashCommand.sendSlashCommand(
|
||||
new Message(this.client, {
|
||||
channel_id: this.id,
|
||||
guild_id: this.guild?.id || null,
|
||||
author: this.client.user,
|
||||
content: '',
|
||||
id: this.client.user.id,
|
||||
}),
|
||||
args,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
exports.Channel = Channel;
|
||||
|
||||
Reference in New Issue
Block a user