首页 > 解决方案 > Discord Bot 没有响应

问题描述

出于某种原因,基本ping pong命令不起作用。我从网站上复制并粘贴了它,但我不确定它有什么问题。

const { Client, Intents } = require('discord.js');
    const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
    client.login('hidden')



client.once('ready', () => {
    console.log('Ready!');
});

client.on('interactionCreate', interaction => {
    if (!interaction.isCommand()) return;

    const { commandName } = interaction;

    if (commandName === 'ping') {
        interaction.reply('Pong.');
    }

});

没有日志错误使它更奇怪。我知道它正在连接,因为当我node index.js在 cmd 面板中执行操作时,机器人会在线显示。

标签: javascriptnode.jsdiscordbots

解决方案


首先,我建议您在开头修复缩进并将client.login调用移至结尾,因为discord.js文档就是这样做的。

此外,您确定您使用的是 Discord.js v13 吗?这些事件是在 v13 中添加的,因此如果您使用 Discord.js v12 运行它,您的机器人将运行,但您的函数将永远不会被调用。

否则,您的代码看起来不错(对我来说),但我不是专家。


推荐阅读