我一直在尝试使用交互创建事件,但不知何故它不起作用。我不知道为什么,而且我没有找到有关此事件的确切文档,只知道它用于执行斜杠命令。但是为了这个目的我使用消息创建事件,并且运行良好。
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.');
}
});
我的怎么了交互创建 event?
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');
}
});
"交互是当用户使用应用程序命令或消息组件时应用程序收到的消息." 不和谐互动 https://discord.com/developers/docs/interactions/receiving-and-responding
messageCreate 监听器几乎会触发其他所有事情。
就您而言,您想做什么来触发交互?也许内置斜线命令?
应用程序命令是应用程序可以注册到 Discord 的命令,我认为内置的斜杠命令与此描述不匹配。因此,为了让您看到交互触发,您必须自己注册一个 applicationCommand (应用程序命令生成器 https://discordjs.guide/popular-topics/builders.html#slash-command-builders)或者使用按钮创建嵌入消息(不和谐按钮 https://discordjs.guide/interactions/buttons.html#building-and-sending-buttons)并单击应触发交互的按钮
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)