Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to check if a server member can send message in a particular channel in discord js?

Suppose there is a server and I have a slash command by which a user can send an embed message. In that command, it have a option to choose in which channel you want to send that embed message and I want to ensure that if a user can send message in the channel they provided in slash command options then only they are able to use that slash command.

I hope someone know how to do this.
thanks in advance!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If you have a channel in channel, a guild in guild, and a user in user, you can get the perms like this:

const permissions = channel.permissionsFor(guild.members.cache.get(user.id));

If you already have the member (as member):

const permissions = channel.permissionsFor(member);

Then you can just check if they have the permissions:

if (permissions.has(PermissionsBitField.Flags.SendMessages)) {
    // member has perms to send in the channel
}

See this page in the guide.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading