Reputation: 53
I want to check if a channel is available (at least to view) to everyone, is there a way to do this?
I've been looking around for a while now and cannot find anything.
Thanks!
Upvotes: 0
Views: 2155
Reputation: 1802
A GuildChannel
has a permissionsFor()
method, which can be used to check the permissions of a user/role in the channel.
To check permissions for @everyone
, access the RoleManager.everyone
property. (guild.roles.everyone
):
// This example assumes that the channel is a guild channel.
client.on("message", (message) => {
const channel = message.channel,
guild = channel.guild,
everyone = guild.roles.everyone;
// see: https://discord.js.org/#/docs/main/stable/class/Permissions?scrollTo=s-FLAGS
if (channel.permissionsFor(everyone).has("VIEW_CHANNEL")) {
console.log("@everyone can view channel!");
} else {
console.log("@everyone cannot view channel!");
}
});
Upvotes: 1