The bot initializes correctly without throwing errors, but it fails to remove messages with *DD. When it’s typed out, I receive the error “tempVariable is not defined”. Can anyone provide guidance on this issue? Your insights would be much appreciated.
make sure you define tempVariable first - something like var tempVariable = null;. if you don’t actually need it, just ditch that check entirely. and watch out for scope issues!
The undefined variable error is what’s breaking your function. Fix the tempVariable declaration first, but also check if your bot has permission to delete messages in that channel. I’ve seen bots that look like they’re working fine but quietly fail on the delete because they’re missing Manage Messages permission. Also, different Discord.js versions handle message deletion differently - newer ones return promises you should catch with .catch() to avoid unhandled rejections. That setTimeout delay seems pointless unless you need it for something specific. It just gives someone else time to delete the message first.
You’re getting that error because tempVariable isn’t declared anywhere. JavaScript throws a ReferenceError when it can’t find a variable. But honestly, I’m not sure what you’re trying to do with that variable - are you preventing spam deletions or adding a cooldown? There might be a better way. Also, message.delete() can fail if your bot doesn’t have permissions or the message is already gone, so you’ll want a try-catch block around it.