我的 Discord.js 机器人 运行(在线并在控制台中显示)但它不会响应命令

My Discord.js bot is running (online and shows in console) but it won't respond to commands

所以,有一天我使用 TeamViewer 连接到我的 RPi3 并告诉它重新启动。完成后,我立即连接到 pi,启动了机器人,看起来它正在正常启动。

当我在 discord 上发送命令时,机器人没有响应。不过,该机器人仍然 运行。

我尝试更改一些代码,但没有任何改变。

代码如下:

[REMOVED]

可能是什么问题?

你的问题是你的 if 语句没有阻塞。

if (message.channel instanceof Discord.DMChannel)
    message.channel.send("``Beep boop! Sorry, I can't respond to direct messages, but you can join the AKAS Gamer's Discord group here: https://discord.gg/QkjQNAr``");
    return

由于缺少括号,您的 return 将始终执行,因为它不是 if 语句的一部分。应该是:

if (message.channel instanceof Discord.DMChannel) {
    message.channel.send("``Beep boop! Sorry, I can't respond to direct messages, but you can join the AKAS Gamer's Discord group here: https://discord.gg/QkjQNAr``");
    return
}

C 风格语言中的常见建议是永远不要省略括号。开始练习。虽然技术上允许单语句条件,但正如您在此处看到的那样,稍后会引起头痛。