pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

Discord 只識別“ping";discord.js 中的命令

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

問題描述

在我的 Discord.JS 機器人中,我設置了多個命令(pingbeep 等),但 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 running npm uninstall discord.js.

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

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

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

相關文檔推薦

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(如何讓我的機器人提及發出該機器人命令的人)
How to fix Must use import to load ES Module discord.js(如何修復必須使用導入來加載 ES 模塊 discord.js)
How to list all members from a specific server?(如何列出來自特定服務器的所有成員?)
Discord bot: Fix ‘FFMPEG not found’(Discord bot:修復“找不到 FFMPEG)
Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服務器時的歡迎消息)
主站蜘蛛池模板: 智能型高压核相仪-自动开口闪点测试仪-QJ41A电雷管测试仪|上海妙定 | 压接机|高精度压接机|手动压接机|昆明可耐特科技有限公司[官网] 胶泥瓷砖胶,轻质粉刷石膏,嵌缝石膏厂家,腻子粉批发,永康家德兴,永康市家德兴建材厂 | 北京网站建设|北京网站开发|北京网站设计|高端做网站公司 | 航空障碍灯_高中低光强航空障碍灯_民航许可认证航空警示灯厂家-东莞市天翔航天科技有限公司 | 首页|光催化反应器_平行反应仪_光化学反应仪-北京普林塞斯科技有限公司 | 天津热油泵_管道泵_天津高温热油泵-天津市金丰泰机械泵业有限公司【官方网站】 | 富森高压水枪-柴油驱动-养殖场高压清洗机-山东龙腾环保科技有限公司 | 矿用履带式平板车|探水钻机|气动架柱式钻机|架柱式液压回转钻机|履带式钻机-启睿探水钻机厂家 | 水平垂直燃烧试验仪-灼热丝试验仪-漏电起痕试验仪-针焰试验仪-塑料材料燃烧检测设备-IP防水试验机 | 针焰试验仪,灼热丝试验仪,漏电起痕试验仪,水平垂直燃烧试验仪 - 苏州亚诺天下仪器有限公司 | 可程式恒温恒湿试验箱|恒温恒湿箱|恒温恒湿试验箱|恒温恒湿老化试验箱|高低温试验箱价格报价-广东德瑞检测设备有限公司 | 煤矿支护网片_矿用勾花菱形网_缝管式_管缝式锚杆-邯郸市永年区志涛工矿配件有限公司 | 环球电气之家-中国专业电气电子产品行业服务网站! | 澳门精准正版免费大全,2025新澳门全年免费,新澳天天开奖免费资料大全最新,新澳2025今晚开奖资料,新澳马今天最快最新图库-首页-东莞市傲马网络科技有限公司 | 急救箱-应急箱-急救包厂家-北京红立方医疗设备有限公司 | 青岛侦探调查_青岛侦探事务所_青岛调查事务所_青岛婚外情取证-青岛狄仁杰国际侦探公司 | 南京PVC快速门厂家南京快速卷帘门_南京pvc快速门_世界500强企业国内供应商_南京美高门业 | 真空乳化机-灌装封尾机-首页-温州精灌 | 全国冰箱|空调|洗衣机|热水器|燃气灶维修服务平台-百修家电 | 拉力机-拉力试验机-万能试验机-电子拉力机-拉伸试验机-剥离强度试验机-苏州皖仪实验仪器有限公司 | 氧化锆陶瓷_氧化锆陶瓷加工_氧化锆陶瓷生产厂家-康柏工业陶瓷有限公司 | 厦门网站建设_厦门网站设计_小程序开发_网站制作公司【麦格科技】 | 钢化玻璃膜|手机钢化膜|钢化膜厂家|手机保护膜-【东莞市大象电子科技有限公司】 | 蒜肠网-动漫,二次元,COSPLAY,漫展以及收藏型模型,手办,玩具的新媒体.(原变形金刚变迷TF圈) | NMRV减速机|铝合金减速机|蜗轮蜗杆减速机|NMRV减速机厂家-东莞市台机减速机有限公司 | 台湾阳明固态继电器-奥托尼克斯光电传感器-接近开关-温控器-光纤传感器-编码器一级代理商江苏用之宜电气 | 印刷人才网 印刷、包装、造纸,中国80%的印刷企业人才招聘选印刷人才网! | 废水处理-废气处理-工业废水处理-工业废气处理工程-深圳丰绿环保废气处理公司 | LED显示屏_LED屏方案设计精准报价专业安装丨四川诺显科技 | 河南正规膏药生产厂家-膏药贴牌-膏药代加工-修康药业集团官网 | 洛阳永磁工业大吊扇研发生产-工厂通风降温解决方案提供商-中实洛阳环境科技有限公司 | 食安观察网| 岩石钻裂机-液压凿岩机-劈裂机-挖改钻_湖南烈岩科技有限公司 | 顺景erp系统_erp软件_erp软件系统_企业erp管理系统-广东顺景软件科技有限公司 | 游动电流仪-流通式浊度分析仪-杰普仪器(上海)有限公司 | 电动打包机_气动打包机_钢带捆扎机_废纸打包机_手动捆扎机 | 广州印刷厂_广州彩印厂-广州艺彩印务有限公司 | 组织研磨机-高通量组织研磨仪-实验室多样品组织研磨机-东方天净 传递窗_超净|洁净工作台_高效过滤器-传递窗厂家广州梓净公司 | 丹佛斯压力传感器,WISE温度传感器,WISE压力开关,丹佛斯温度开关-上海力笙工业设备有限公司 | 成都亚克力制品,PVC板,双色板雕刻加工,亚克力门牌,亚克力标牌,水晶字雕刻制作-零贰捌广告 | 电镀整流器_微弧氧化电源_高频电解电源_微弧氧化设备厂家_深圳开瑞节能 |