简体   繁体   English

Discord 机器人没有响应

[英]Discord bot isn't responding

For some reason the basic ping pong command isn't working.出于某种原因,基本的 ping pong 命令不起作用。 I basically copy and pasted from a website but I am not sure what is wrong with you.我基本上是从网站复制和粘贴的,但我不确定你有什么问题。

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.');
    }

});

There is no log error which makes it weirder.没有日志错误使它变得更奇怪。 I know it is connecting because the bot appears online when I do a node index.js in the cmd panel.我知道它正在连接,因为当我在 cmd 面板中执行 node index.js 时,bot 会在线显示。 Any help is welcomed!欢迎任何帮助!

Firstly, I recommend that you fix the indentation at the beginning and move the client.login call to the end, as that's how the discord.js docs do it.首先,我建议您在开头修复缩进并将client.login调用移到最后,因为discord.js文档就是这样做的。

Additionally, are you sure you're using Discord.js v13?另外,您确定您使用的是 Discord.js v13 吗? These events were added in v13, so if you run it with Discord.js v12, your bot will run, but your functions will never be called.这些事件是在 v13 中添加的,因此如果您使用 Discord.js v12 运行它,您的机器人将运行,但您的函数将永远不会被调用。

Otherwise, your code looks good (to me), but I'm not an expert.否则,你的代码看起来不错(对我来说),但我不是专家。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM