简体   繁体   中英

How to check if @everyone can send messages in specific Discord channel?

Basically, I need a function that returns true or false depending on whether a specified channel has the SEND_MESSAGES permission for @everyone checked. Does anyone know how to do this?

First you need to get both the Role and the Channel object to check the permission for the role in that particular channel. And then you check the permissions in that particular channel has a particular permission or not.

Eg: Checking with the role object :

let role = message.guild.roles.cache.get('roleid');
let channel = message.guild.channels.cache.get('channelid');
if(role.permissionsIn(channel).has('Permissions.FLAGS')){
    //do your thing.
}

Eg: Checking with the channel object :

let role = message.guild.roles.cache.get('roleid');
let channel = message.guild.channels.cache.get('channelid');
if(channel.permissionsFor(role).has('Permissions.FLAGS')){
    //do your thing.
}

Note : The everyone role ID is same as the guild ID. So use the guild ID to get the everyone role object.

Reference: permissionsFor() , permissionsIn() , Permissions.FLAGS .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM