【发布时间】:2021-12-15 19:16:40
【问题描述】:
我一直在尝试使用 interactionCreate 事件,但不知何故它不起作用。我不确定为什么,也没有找到有关此事件的确切文档,只是它用于执行斜杠命令。但是为此我使用 messageCreate 事件,它工作正常。
const Event = require('../handlers/Event.js');
module.exports = new Event('messageCreate', (client, message) => {
if (!message.content.startsWith(client.prefix) || message.author.bot) return;
const args = message.content.substring(client.prefix.length).split(/ +/);
try {
const command = client.commands.find(cmd => cmd.name == args[0] || cmd.alias == args[0]);
command.run(message, args, client);
} catch (error) {
message.channel.send('Wrong command.');
}
});
我的 interactionCreate 事件有什么问题?
const Event = require('../handlers/Event.js');
module.exports = new Event('interactionCreate', async (interaction) => {
if (!interaction.isCommand()) return;
if (interaction.commandName === 'join') {
await interaction.reply('join');
}
});
【问题讨论】:
标签: javascript node.js discord.js