Search code examples
discorddiscord.js

Discord.js changing perms


Let say I want to make a lock command (making only admins be able to say something in a channel) and I want a specific role to be overwrite (not @everyone). How could I do that?

To simply it. How can I disable SEND_MESSAGE for a specific role? /


Solution

  • You will be able to achieve this via GuildChannel.permissionOverwrites which returns the PermissionOverwriteManager class. Within that class, you will be able to use the .edit() method which

    Edits permission overwrites for a user or role in this channel, or creates an entry if not already present.

    In the first parameter of the .edit() method, you can input the role ID as a string, and in the options, you can input the property, or as known as the permission, with a value of true to enable or value false to disable.

    The documentation for the PermissionOverwriteManager.edit() method includes this example:

    // Edit or Create permission overwrites for a message author
    message.channel.permissionOverwrites.edit(message.author, {
      SEND_MESSAGES: false
    })
      .then(channel => console.log(channel.permissionOverwrites.cache.get(message.author.id)))
      .catch(console.error);