JavaScript Discord Bot Not Working - Help Needed

Hey everyone, I’m having trouble with my Discord bot. It’s supposed to ban certain words, but it’s not working right now. The main issue seems to be in lines 100-115 of the code.

Here’s what’s happening:

  • The Start.bat window opens and closes quickly
  • The bot is for my Discord server
  • It’s based on a bot called The Parrot
  • I’ve tried to modify it to ban specific words

Has anyone run into this before? Any ideas on how to fix it? I really need this bot up and running for my server. Thanks in advance for any help!

Here’s a simplified version of the problematic part:

bot.on('message', message => { 
    var sender = message.author;
    var msg = message.content.toUpperCase();
    var prefix = '>'

    if (sender.id === 'SOME_ID') { 
        return;
    }

    if (msg.includes('BAD_WORD')) {
        message.delete();
        message.author.send('This word is not allowed. Be careful or you might get banned!')
    }
}

Can anyone spot what might be wrong here?

hey mate, maybe the prob is with your message event. check ur bot token and perms, and note the missing ) after bot.on(. also, change ‘SOME_ID’ to an actual id. use console.log() to debug. hope it helps!

I’ve dealt with similar bot issues before. Your problem likely stems from improper event handling or API connection. First, double-check your bot token and permissions. Ensure you’re closing the bot.on() function properly - a missing parenthesis could crash the bot instantly.

Replace ‘SOME_ID’ with an actual user ID if you’re trying to ignore specific users. Consider implementing a more sophisticated word filter; exact matches are easily circumvented. Adding console.log() statements throughout your code can help pinpoint where things are going wrong.

If these steps don’t resolve the issue, verify your Node.js version and look for conflicts with other bot functions. Discord’s API occasionally changes, so ensure your code is up-to-date with their latest requirements.

I’ve encountered similar issues with Discord bots before. The problem might be in how you’re handling the message event. Here’s what I’d suggest:

  1. Make sure you’re properly connecting to Discord’s API. Check if your bot token is correct and if you have the necessary permissions.

  2. Your code seems to be missing the closing parenthesis for the bot.on() function. That could cause the bot to crash immediately.

  3. The ‘SOME_ID’ in the sender.id check should be replaced with an actual user ID if you’re trying to ignore messages from a specific user.

  4. Consider using a more robust word filter system. The current setup only checks for exact matches, which can be easily bypassed.

  5. Add some console.log() statements in your code to help debug. This way, you can see what’s happening when the bot receives a message.

If these don’t solve the issue, you might want to check your Node.js version or any potential conflicts with other bot functions. Good luck with your bot!