久久久久久久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í)的歡迎消息)
主站蜘蛛池模板: av中文字幕在线 | 亚洲人人 | 欧美一区2区三区4区公司 | 综合网伊人 | 黄色片av| 精品视频在线免费观看 | 欧美日韩一区在线 | 亚洲成人在线免费 | 爱草视频 | 国产一级成人 | 国产高清精品一区二区三区 | 日韩午夜网站 | 韩日一区二区 | 日本一区不卡 | 欧美一区二区三区在线观看 | 羞羞的视频在线观看 | 亚洲精品久久久久久下一站 | 亚洲 精品 综合 精品 自拍 | 成人亚洲视频 | 久久久久国产一区二区三区不卡 | 亚洲一区中文字幕 | 夜夜草导航 | 青春草国产 | 黄在线免费观看 | 国产成人精品a视频一区www | 国产精品久久久久久久模特 | 在线免费观看a级片 | 午夜视频在线免费观看 | 国产一级免费视频 | 91视视频在线观看入口直接观看 | 一区二区三区四区毛片 | 久草视频在线播放 | 国产亚洲网站 | 亚洲精品中文字幕 | 999久久久精品 | 国产免费看| 国产清纯白嫩初高生在线播放视频 | 91在线网站 | 99热在线免费 | 一区二区三区在线免费 | 成人中文网 |