問題描述
在我的 Discord.JS 機器人中,我設置了多個命令(ping
、beep
等),但 Discord 只識別ping".我嘗試了多種設置,都一樣.
這是我的代碼:
const { Client, Intents } = require('discord.js');const { token } = require('./config.json');const client = new Client({ 意圖:[Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });client.once('準備好了', () => {console.log('準備好了!');});client.on('interactionCreate', 異步交互 => {如果 (!interaction.isCommand()) 返回;const { commandName: command } = 交互;如果(命令 === 'ping'){等待交互.回復('乒乓!');} else if (command === 'beep') {等待交互.回復('Boop!');} else if (command === 'server') {await interaction.reply(`服務器名稱:${interaction.guild.name}
成員總數:${interaction.guild.memberCount}`);} else if (command === 'user-info') {awaitinteraction.reply(`你的用戶名:${interaction.user.username}
你的ID:${interaction.user.id}`);}});client.login(token);
這里是/"時的 Discords 命令視圖.是輸入
如您所見,ping
是唯一被 discord 識別的東西.
還值得注意的是,ping"命令具有我設置的原始描述的描述,因此問題似乎是 Discord 不會在每次腳本更改時更新命令.但是,我不知道如何解決這個問題.
您好像只注冊了 ping 命令.您必須分別注冊每個斜杠命令.
我猜你之前在某個圖塊上注冊了 slashcommand,從那以后就沒有刪除它.您僅在代碼示例中響應斜杠命令,但您必須首先創建它們.查看這里了解如何這樣做.
<塊引用>注冊一個全局命令可能需要一小時,所以請耐心等待.如果你沒問題,只有一個公會的斜線命令,你也可以只創建 guildCommands.這些都在幾分鐘內啟動并運行(最多 10 分鐘)
這是一個簡單的命令,您可以使用它更新斜杠命令(這是 docs)
client.on('messageCreate', async message => {if (!client.application?.owner) 等待 client.application?.fetch();if (message.content.toLowerCase() === '!deploy' && message.author.id === client.application?.owner.id) {常量數據 = [{名稱:'平',description: '用 Pong 回復!',},{名稱:'乒乓',description: '用 Ping 回復!',},];const commands = await client.application?.commands.set(data);控制臺.log(命令);}});
<塊引用>
注意:您必須運行 discord.js 的主分支(又名 Discord.js V13
).如果你還沒有安裝它,你可以通過運行:npm install discord.js@latest
來安裝它.確保,您已經卸載了正常"的通過運行 npm uninstall discord.js
預先依賴 discord.js.
如果你不確定你當前安裝的是什么版本,只需運行 npm list
In my Discord.JS bot, I have multiple commands setup (ping
, beep
, etc.) but Discord only recognizes "ping". I have tried multiple setups, and all are the same.
Here is my code:
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}
Total members: ${interaction.guild.memberCount}`);
} else if (command === 'user-info') {
await interaction.reply(`Your username: ${interaction.user.username}
Your ID: ${interaction.user.id}`);
}
});
client.login(token);
And here is Discords command view when "/" is enter
As you can see, ping
is the only thing being recognized by discord.
It is also worth noting the ‘ping’ command has a description which the original description I setup, so it seems like issue is that Discord is not updating the commands each time the script changes. But, I don’t know how to resolve that issue.
It seems like you only registered the ping command. You have to register each slash command individually.
I guess you registered the slashcommand some tile earlier, and have not removed it since. You are only responding in your code example to slashcommands, but you have to create them in the first hand. Check here on how to do that.
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)
Here is a simple command, with which you can update the slashcommands (this is staright from the 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
這篇關于Discord 只識別“ping";discord.js 中的命令的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!