問題描述
所以,有一天我使用 TeamViewer 連接到我的 RPi3 并告訴它重新啟動.完成后,我連接到 pi,啟動了 bot,它看起來正常啟動.
So, one day I was using TeamViewer to connect to my RPi3 and told it to reboot. As soon as it finished, I connected to the pi, started the bot, and it looked like it was starting up properly.
當我在 discord 上發送命令時,機器人沒有響應.機器人仍在運行.
When I went to send a command on discord, the bot didn't respond. The bot is still running though.
我嘗試更改一些代碼,但沒有任何改變.
I tried changing some of the code, but nothing changed.
代碼如下:
[REMOVED]
可能是什么問題?
推薦答案
你的問題是你的 if 語句沒有阻塞.
Your problem is lack of blocking of your if statement.
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 語句的一部分.應該是:
With the lack of bracketing, your return will always execute as it is not part of the if statement. It should be:
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 風格語言中的常見建議是永遠不要省略括號.進入那個練習.雖然從技術上講,單語句條件是允許的,但正如您在此處看到的那樣,它稍后會引起頭痛.
Common recommendation in C-style languages is to never omit the brackets. Get into that practice. While it is technically allowable for single statement conditionals, it will cause headaches later as you've seen here.
這篇關于我的 Discord.js 機器人正在運行(在線并在控制臺中顯示)但它不會響應命令的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!