【发布时间】:2021-10-11 23:31:47
【问题描述】:
在我的 Discord.JS 机器人中,我设置了多个命令(ping、beep 等),但 Discord 只识别“ping”。我尝试了多种设置,都一样。
这是我的代码:
const { Client, Intents } = require('discord.js');
const { token } = require('./config.json');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
client.once('ready', () => {
console.log('Ready!');
});
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
const { commandName: command } = interaction;
if (command === 'ping') {
await interaction.reply('Pong!');
} else if (command === 'beep') {
await interaction.reply('Boop!');
} else if (command === 'server') {
await interaction.reply(`Server name: ${interaction.guild.name}\nTotal members: ${interaction.guild.memberCount}`);
} else if (command === 'user-info') {
await interaction.reply(`Your username: ${interaction.user.username}\nYour ID: ${interaction.user.id}`);
}
});
client.login(token);
这是输入“/”时的 Discords 命令视图
如您所见,ping 是唯一被 discord 识别的东西。
还值得注意的是,“ping”命令具有我设置的原始描述的描述,因此问题似乎是 Discord 不会在每次脚本更改时更新命令。但是,我不知道如何解决这个问题。
【问题讨论】:
-
使用单独的 if 语句时是否会出现同样的问题?看起来不和谐将 if else if 作为一个语句..
-
命令文件也会发生这种情况,所以我怀疑这是问题所在。无论如何我会调查的。
-
我会看看我在帖子底部所做的编辑
-
你在哪里注册命令?您可以将该代码添加到您的问题中吗?
-
请注意,您提供的代码中的任何内容均不对不和谐中显示的内容(作为命令)负责。
标签: javascript node.js discord discord.js