久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Discord 只識(shí)別“ping";discord.js 中的命令

Discord only recognizing quot;pingquot; command in discord.js(Discord 只識(shí)別“ping;discord.js 中的命令)
本文介紹了Discord 只識(shí)別“ping";discord.js 中的命令的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

在我的 Discord.JS 機(jī)器人中,我設(shè)置了多個(gè)命令(ping、beep 等),但 Discord 只識(shí)別ping".我嘗試了多種設(shè)置,都一樣.

這是我的代碼:

const { Client, Intents } = require('discord.js');const { token } = require('./config.json');const client = new Client({ 意圖:[Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });client.once('準(zhǔn)備好了', () => {console.log('準(zhǔn)備好了!');});client.on('interactionCreate', 異步交互 => {如果 (!interaction.isCommand()) 返回;const { commandName: command } = 交互;如果(命令 === 'ping'){等待交互.回復(fù)('乒乓!');} else if (command === 'beep') {等待交互.回復(fù)('Boop!');} else if (command === 'server') {await interaction.reply(`服務(wù)器名稱:${interaction.guild.name}
成員總數(shù):${interaction.guild.memberCount}`);} else if (command === 'user-info') {awaitinteraction.reply(`你的用戶名:${interaction.user.username}
你的ID:${interaction.user.id}`);}});client.login(token);

這里是/"時(shí)的 Discords 命令視圖.是輸入

如您所見,ping 是唯一被 discord 識(shí)別的東西.

還值得注意的是,ping"命令具有我設(shè)置的原始描述的描述,因此問題似乎是 Discord 不會(huì)在每次腳本更改時(shí)更新命令.但是,我不知道如何解決這個(gè)問題.

解決方案

您好像注冊(cè)了 ping 命令.您必須分別注冊(cè)每個(gè)斜杠命令.

我猜你之前在某個(gè)圖塊上注冊(cè)了 slashcommand,從那以后就沒有刪除它.您僅在代碼示例中響應(yīng)斜杠命令,但您必須首先創(chuàng)建它們.查看這里了解如何這樣做.

<塊引用>

注冊(cè)一個(gè)全局命令可能需要一小時(shí),所以請(qǐng)耐心等待.如果你沒問題,只有一個(gè)公會(huì)的斜線命令,你也可以只創(chuàng)建 guildCommands.這些都在幾分鐘內(nèi)啟動(dòng)并運(yùn)行(最多 10 分鐘)


這是一個(gè)簡(jiǎn)單的命令,您可以使用它更新斜杠命令(這是 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) {常量數(shù)據(jù) = [{名稱:'平',description: '用 Pong 回復(fù)!',},{名稱:'乒乓',description: '用 Ping 回復(fù)!',},];const commands = await client.application?.commands.set(data);控制臺(tái).log(命令);}});

<塊引用>

注意:您必須運(yùn)行 discord.js 的主分支(又名 Discord.js V13).如果你還沒有安裝它,你可以通過運(yùn)行:npm install discord.js@latest來安裝它.確保,您已經(jīng)卸載了正常"的通過運(yùn)行 npm uninstall discord.js 預(yù)先依賴 discord.js.

<塊引用>

如果你不確定你當(dāng)前安裝的是什么版本,只需運(yùn)行 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 running npm uninstall discord.js.

If you are not sure what version you currently have installed, simply run npm list

這篇關(guān)于Discord 只識(shí)別“ping";discord.js 中的命令的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

discord.js v12: How do I await for messages in a DM channel?(discord.js v12:我如何等待 DM 頻道中的消息?)
how to make my bot mention the person who gave that bot command(如何讓我的機(jī)器人提及發(fā)出該機(jī)器人命令的人)
How to fix Must use import to load ES Module discord.js(如何修復(fù)必須使用導(dǎo)入來加載 ES 模塊 discord.js)
How to list all members from a specific server?(如何列出來自特定服務(wù)器的所有成員?)
Discord bot: Fix ‘FFMPEG not found’(Discord bot:修復(fù)“找不到 FFMPEG)
Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服務(wù)器時(shí)的歡迎消息)
主站蜘蛛池模板: 人人亚洲 | 91精品国产欧美一区二区 | 国产99热精品 | 国产精品九九视频 | 久久中文字幕av | 成人免费视频网址 | 中文字幕动漫成人 | 国产精品1区2区3区 一区中文字幕 | 二区视频 | 久久久国产精品 | 羞羞色在线观看 | 男女羞羞视频在线观看 | 国产伦精品一区二区三毛 | 午夜视频免费在线观看 | 黄色网址在线播放 | 亚洲午夜精品在线观看 | 亚洲第一在线 | 国产伊人久久久 | 2019天天干天天操 | 免费视频一区二区 | 欧美性一区二区三区 | 本道综合精品 | 九九免费视频 | 久久免费观看一级毛片 | 国产高清视频一区二区 | 精品一区国产 | 97视频人人澡人人爽 | 自拍偷拍亚洲欧美 | 日韩欧美在线观看一区 | 成年人免费看 | 久久久久se | 这里精品| jlzzjlzz国产精品久久 | 亚洲欧洲精品一区 | 午夜精品久久久久久久久久久久 | 亚洲午夜精品 | 九九视频网 | 欧美一区二区三区在线 | 日日操夜夜操天天操 | 福利成人 | 国产高清视频一区二区 |