我正试图为我的discord机器人创建一个斜杠命令,但我不知道在命令发出时如何执行代码我要使用的代码将向其他通道发送消息(args:message)这是我想要使用的代码
const channel = client.channels.cache.find(c => c.id == "834457788846833734") channel.send(Message)
d5vmydt91#
你需要倾听一个事件 interactionCreate 或 INTERACTION_CREATE . 看到下面的代码,还没有测试过任何东西,希望它能工作。对于discord.js v12:
interactionCreate
INTERACTION_CREATE
client.ws.on("INTERACTION_CREATE", (interaction) => { // Access command properties const commandId = interaction.data.id; const commandName = interaction.data.name; // Do your stuff const channel = client.channels.cache.find(c => c.id == "834457788846833734"); channel.send("your message goes here"); // Reply to an interaction client.application.interactions(interaction.id, interaction.token).callback.post({ data: { type: 4, data: { content: "Reply message" } } }); });
对于discord.js v13:
client.on("interactionCreate", (interaction) => { if (interaction.isCommand()) { // Access command properties const commandId = interaction.commandId; const commandName = interaction.commandName; // Do your stuff const channel = client.channels.cache.find(c => c.id == "834457788846833734") channel.send("your message goes here"); // Reply to an interaction interaction.reply("Reply message"); } });
1条答案
按热度按时间d5vmydt91#
你需要倾听一个事件
interactionCreate
或INTERACTION_CREATE
. 看到下面的代码,还没有测试过任何东西,希望它能工作。对于discord.js v12:
对于discord.js v13: