简体   繁体   中英

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

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.

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.

Here's the code:

[REMOVED]

What could be the problem?

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

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
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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