問題描述
所以,有一天我使用 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.
當(dāng)我在 discord 上發(fā)送命令時,機(jī)器人沒有響應(yīng).機(jī)器人仍在運(yùn)行.
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 將始終執(zhí)行,因?yàn)樗皇?if 語句的一部分.應(yīng)該是:
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 風(fēng)格語言中的常見建議是永遠(yuǎn)不要省略括號.進(jìn)入那個練習(xí).雖然從技術(shù)上講,單語句條件是允許的,但正如您在此處看到的那樣,它稍后會引起頭痛.
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.
這篇關(guān)于我的 Discord.js 機(jī)器人正在運(yùn)行(在線并在控制臺中顯示)但它不會響應(yīng)命令的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!