Skip to content Skip to sidebar Skip to footer

Discord.js Mute Command Only Sends Embed For Incorrect Command

So im making a mute command for my discord bot which finds if a 'Muted' role exists and if it doesn't then the bot creates a 'Muted' role and then gives that role to the mentioned

Solution 1:

We can see your code:


    let role = 'Muted'
    let muterole = message.guild.roles.cache.find(x => x.name === role);
    if (typeof muterole === undefined) {
      message.guild.roles.create({
        data: {
          name: 'muted',
          color: '#ff0000',
          permissions: {
              SEND_MESSAGES: false,
              ADD_REACTIONS: false,
              SPEAK: false
          }
        },
        reason: 'to mute people',
      })
      .catch(err => console.log(err).then(message.channel.send('Mute Role could not be created')))
    } 

if (muterole = undefined) return message.channel.send(Embedhelp);

and this will stop the runnning while muterole is undefined. Since the muterole is not able to create, it will stop running while running to the if muterole line. To fix the problem, while creating a role in discord.js, permissions flag is needed only when you want to add the permissions to the role. You don't have to put false/deny to specific which permissions you don't want in the role since it's marking all the permissions as false if you don't't label them out. Therefore, we could replace the permissions with only bracket:

if (muterole === undefined) {
    message.guild.roles.create({
        data: {
            name: 'muted',
            color: '#ff0000',
            permissions: []
        },
        reason: 'to mute people',
    })
        .catch(err => console.log(err).then(message.channel.send('Mute Role could not be created')))
}

Post a Comment for "Discord.js Mute Command Only Sends Embed For Incorrect Command"