Skip to content
Advertisement

I am trying to make a discord.js command that creates a role named “MUTED” and overwrites all the channel permission to set “Send message” to false [closed]

I want to make it so that it creates the role and then overwrites the permissions in every channel that exists in the server.

module.exports = {
    name: "createmuterole",
    description: "creates a muted role for mute command to work",
    guildOnly: true,
    execute(message, args) {
        if (!message.member.permissions.has("MANAGE_SERVER")) return message.channel.send(`You donot have the required permission to perform this command, ${message.author.username}`);
        const Muted = message.guild.roles.cache.find((role) => role.name === "Muted");
        message.guild.roles.create({
            data: {
                name: "Muted",
                color: "#000000",
                permissions: [],
            },
        });

        message.guild.updateOverwrite(guild.channels.roles.Muted, { SEND_MESSAGES: false }); //this part doesn't seem to be working
        message.channel.send("Role sucessfully Created");
    },
};

Advertisement

Answer

This example should provide the basic structure for muting people. Keep in mind that this following example mutes people by id, so you’re going to have to modify that so it’s for roles.

guild.channels.cache.forEach(async (channel, id) => {
    await channel.overwritePermissions([
      {
        id: member.id,
        deny: ["SEND_MESSAGES"],
      },
    ]);
  });

What this does is override each channel permissions and denies the permission to send messages for the id.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement