Search code examples
javascriptbotsraspberry-pi3discord.js

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?


Solution

  • 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.