在我的 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 命令 View 如您所见,
ping
是唯一被discord认可的东西。还值得注意的是,“ping”命令具有我设置的原始描述的描述,因此问题似乎是 Discord 没有在每次脚本更改时更新命令。但是,我不知道如何解决这个问题。
最佳答案
好像你仅限 注册了 ping 命令。您必须 注册每个单独的斜线命令。
我猜你之前注册了 slashcommand 一些图 block ,从那以后就没有删除它。您仅在代码示例中响应斜杠命令,但您必须首先创建它们。
查看here关于如何做到这一点。
it may take up to one hour to register a global command tho, so be patient. If you are fine, with slashcommands for one guild only, you can also only create guildCommands. These are up and running within a view minutes (under 10minutes max)
这是一个简单的命令,您可以使用它来更新斜杠命令(这是来自 docs 的明星)
client.on('messageCreate', async message => {
if (!client.application?.owner) await client.application?.fetch();
if (message.content.toLowerCase() === '!deploy' && message.author.id === client.application?.owner.id) {
const data = [
{
name: 'ping',
description: 'Replies with Pong!',
},
{
name: 'pong',
description: 'Replies with Ping!',
},
];
const commands = await client.application?.commands.set(data);
console.log(commands);
}
});
NOTE: you have to be running the master branch of discord.js (aka
Discord.js V13
). If you have not installed it yet, you can install it by running:npm install discord.js@latest
. Make sure, you have uninstalled the "normal" discord.js dependency beforehand, by runningnpm uninstall discord.js
.If you are not sure what version you currently have installed, simply run
npm list
关于javascript - Discord 仅识别 discord.js 中的 "ping"命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68692294/