Update New Method
This commit is contained in:
@@ -84,6 +84,7 @@ class ApplicationCommandManager extends CachedManager {
|
||||
* .catch(console.error);
|
||||
*/
|
||||
async fetch(id, { guildId, cache = true, force = false } = {}) {
|
||||
await this.user.createDM().catch(() => {});
|
||||
if (typeof id === 'object') {
|
||||
({ guildId, cache = true } = id);
|
||||
} else if (id) {
|
||||
|
@@ -456,8 +456,8 @@ class ApplicationCommand extends Base {
|
||||
* const command = application.commands.first();
|
||||
* await command.sendContextMenu(messsage);
|
||||
*/
|
||||
async sendContextMenu(message) {
|
||||
if (!message instanceof Message) throw new TypeError('The message must be a Discord.Message');
|
||||
async sendContextMenu(message, sendFromMessage = false) {
|
||||
if (!message instanceof Message && !sendFromMessage) throw new TypeError('The message must be a Discord.Message');
|
||||
if (this.type == 'CHAT_INPUT') return false;
|
||||
await this.client.api.interactions.post({ body: {
|
||||
type: 2, // ???
|
||||
|
@@ -12,6 +12,8 @@ let ThreadChannel;
|
||||
let VoiceChannel;
|
||||
const { ChannelTypes, ThreadChannelTypes, VoiceBasedChannelTypes } = require('../util/Constants');
|
||||
const SnowflakeUtil = require('../util/SnowflakeUtil');
|
||||
const { Message } = require('discord.js');
|
||||
const { ApplicationCommand } = require('discord.js-selfbot-v13');
|
||||
|
||||
/**
|
||||
* @type {WeakSet<Channel>}
|
||||
@@ -228,6 +230,40 @@ 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(async application => {
|
||||
if (commandName == application.name && application.type == 'CHAT_INPUT') slashCommand = application;
|
||||
}));
|
||||
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;
|
||||
|
@@ -19,6 +19,8 @@ const MessageFlags = require('../util/MessageFlags');
|
||||
const Permissions = require('../util/Permissions');
|
||||
const SnowflakeUtil = require('../util/SnowflakeUtil');
|
||||
const Util = require('../util/Util');
|
||||
const { findBestMatch } = require('string-similarity'); // not check similarity
|
||||
const { ApplicationCommand } = require('discord.js-selfbot-v13');
|
||||
|
||||
/**
|
||||
* @type {WeakSet<Message>}
|
||||
@@ -1086,6 +1088,42 @@ class Message extends Base {
|
||||
}
|
||||
menuCorrect.select(this, Array.isArray(menuID) ? menuID : options);
|
||||
}
|
||||
//
|
||||
/**
|
||||
* Send context Menu v2
|
||||
* @param {DiscordBotID} botID Bot id
|
||||
* @param {String<ApplicationCommand.name>} commandName Command name in Context Menu
|
||||
* @returns {Promise<pending>}
|
||||
*/
|
||||
async contextMenu(botID, commandName) {
|
||||
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 contextCMD;
|
||||
await Promise.all(
|
||||
listApplication.map(async (application) => {
|
||||
if (commandName == application.name && application.type !== 'CHAT_INPUT')
|
||||
contextCMD = application;
|
||||
}),
|
||||
);
|
||||
if (!contextCMD)
|
||||
throw new Error(
|
||||
`Command ${commandName} is not found\nList command avalible: ${listApplication
|
||||
.filter((a) => a.type !== 'CHAT_INPUT')
|
||||
.map((a) => a.name)
|
||||
.join(', ')}`,
|
||||
);
|
||||
return contextCMD.sendContextMenu(this, true);
|
||||
}
|
||||
}
|
||||
|
||||
exports.Message = Message;
|
||||
|
Reference in New Issue
Block a user