Search code examples
javascriptdiscord.js

Discord.js check if bot is capable of sending embeds into a specific channel


I'm trying to figure out how to check if my bot has permission to send messages and include embeds into a specific channel.

I have found the following code that returns a boolean if a specific member has a permission in a specific channel. but I'm unsure how to perform the same action for the bot itself.

message.member.permissionIn('channel_id').hasPermission('SEND_MESSAGES');

Solution

  • None of the other answers explain how the get the GuildMember object, so I'll try explaining it. All you need to do is get the GuildMember from your client. To do this, use client.guilds.cache.get(guild_id).members.me to your the bot's GuildMember, then from there you can use the same code. Try this:

    client.guilds.cache.get(guild_id).members.me.permissionsIn(channel_id).has('SEND_MESSAGES')
    

    where guild_id is the server ID and channel_id is the channel ID.

    Alternatively, if you already have the Message object, then you can just the the Guild from there. Like this:

    message.guild.members.me.permissionsIn(channel_id).has('SEND_MESSAGES')