【问题标题】:My Discord.js bot is running (online and shows in console) but it won't respond to commands我的 Discord.js 机器人正在运行(在线并在控制台中显示)但它不会响应命令
【发布时间】:2020-05-28 06:47:33
【问题描述】:

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

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

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

代码如下:

[REMOVED]

可能是什么问题?

【问题讨论】:

    标签: javascript bots raspberry-pi3 discord.js


    【解决方案1】:

    你的问题是你的 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 风格语言中的常见建议是永远不要省略括号。进入那个练习。虽然它在技术上对于单语句条件是允许的,但正如您在此处看到的那样,它稍后会引起头痛。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-21
      • 2021-11-10
      • 2021-08-30
      • 2021-12-03
      • 1970-01-01
      • 2021-09-04
      • 2021-06-25
      相关资源
      最近更新 更多