Reputation: 35
I have if (!message.guild.me.hasPermission("SEND_MESSAGES")) return;
in my code but when I disable the bot's permission to Send Messages it gives me an error, (node:2504) UnhandledPromiseRejectionWarning: DiscordAPIError: Missing Permissions
. How could I possibly solve this issue so I won't get the error when my bot cannot send messages into a chat.
Upvotes: 1
Views: 1328
Reputation: 1464
It might be because the permission required isn't SEND_MESSAGES
.
For example, if you are coding a ban
command, you would also need to check if the bot has the BAN_MEMBERS
permissions.
If it was an add-role
command, you would have to check if the bot highest role is higher than the role it needs to assign.
Upvotes: 0
Reputation: 21
You could possibly use a try catch block to catch the exception and then just don't print the error.
like :
try{
if (!message.guild.me.hasPermission("SEND_MESSAGES")) return;
}catch{}
Upvotes: 1
Reputation: 14570
Do this before the message event
Try this:
if (message.author.bot) {
return;
} else {
//do soemthing if user is not a bot
}
Upvotes: 1