Mute command help

const prefix = “!”

client.on(‘message’, message => {
if(message.content.startsWith(prefix + ‘mute’)){
let user = message.mentions.users.first();
let role = message.guild.roles.find(r => r.name === ‘Muted’);
if(!role) message.guild.createRole({name: ‘Muted’});
if(user.bot){
return message.channel.send(I can't mute ${user} because he is a bot);
}
if(user.hasPermission(‘ADMINISTRATOR’)) {
return message.channel.send(I can't mute ${user} because he is staff);
}

if(!user){
    message.channel.send(`There's no person to mute tho`);
}
message.guild.channels.forEach(f => {
    f.overwritePermissions(role, {
        SEND_MESSAGES: false
    });
    user.addRole(role);
   
});
 message.channel.send(`I muted ${user}`);

}
});

client.on(‘message’, message => {
if(message.content.startsWith(prefix + ‘unmute’)){
let user = message.mentions.users.first();

let role = message.guild.roles.find(r => r.name === 'Muted');

if(!user.roles.has(role)) {
return message.channel.send(He is not muted);
}
user.removeRole(role).then(message.channel.send(Unmuted ${user}));

}
});

This is my code, I just don’t know how to fix it because it isnt working :confused:

What exactly doesn’t work?

It doesn’t give the role to the user.

I think the bot must have sufficient permissions to give roles to users…

What is the exact error message?

It just doesn’t add the role.

The bot has EVERY permission.

Try message.mentions.members.first();

Hey @Krxvee,

Can you do

.catch(console.error)

Under user.addRole(role) ?

That worked. But the unmute doesn’t work with taking the role off.

This quote above is in the unmute command.

Try changing that to this as well:

let user = message.mentions.members.first();

I did that. But now it says that they’re not muted and it doesn’t take the role away.

Instead of this, can you try:

let ifHasRole = message.member.roles.find(role => role.name === 'Muted');
if(!ifHasRole){
return message.channel.send('He is not muted');
}
1 Like

Omg! thank you so much. This works!!

poi ci sono io che cerco di farlo ma nn so che sbaglio, ho seguito instruzioni e tutorial, sia da youtube che google, ma per vari motivi non capisco.
1 non so tanto l’inglese :sweat_smile:
2 ho iniziato da tipo 3 settimane a programmare e ho gia comandi facili:
ping, server-info, ban, kick, clear, invite e help

però l’help vorrei farlo con le reazioni, non so se mi capisco… potreste aiutarmi?

Non … davvero non capivo cosa stavi cercando di dire. Utilizza Google Translate e traduci ciò di cui hai bisogno in inglese.

(Traduzione con Google Translate)
(Translated to Italian based on language.)

oh ok sorry

then there is me trying to do it but nn I know that I am wrong, I followed instructions and tutorials, both from youtube and google, but for various reasons I do not understand.
1 I don’t know so much english :sweat_smile:
2 I started planning for like 3 weeks and I already have easy commands:
ping, server-info, ban, kick, clear, invite and help

but the help I would like to do with the reactions, I do not know if I understand… could you help me?

Go ahead and make a new topic describing your specific problem with reactions, and hopefully this community will be able to help you :slight_smile:

2 Likes

This is my code for my discord bot but nothing works it is something like krxvees code but mine does not work

client.on(“message”, message => {
let user = message.mentions.users.first();
if(message.content.startsWith(prefix + “mute”)){
let user = message.mentions.users.first();
let role = message.guild.roles.find(r => r.name === “Muted”);
if(!role) message.guild.createRole({name: “Muted”});
if(user.bot){
return message.channel.send(“I cant mute {user} because he is a bot"); } if(user.hasPermission("ADMINISTRATOR")) { return message.channel.send("I can't mute {user} because he is staff”);
}
if(!user){
message.channel.send(There's no person to mute tho);
}
message.guild.channels.forEach(f => {
f.overwritePermissions(role, {
SEND_MESSAGES: false
});
user.addRole(role);

});
message.channel.send(I muted ${user});
}
});
client.on(“message”, message => {
if(message.content.startsWith(prefix + “unmute”)){
let user = message.mentions.users.first();
let role = message.guild.roles.find(r => r.name === ‘Muted’);
if(!user.roles.has(“Muted”)) {
return message.channel.send(“He is not muted”);
}
user.removeRole(“Muted”).then(message.channel.send(“Unmuted ${user}”));

}
});
let ifHasRole = message.member.roles.find(role => role.name === ‘Muted’);
if(!ifHasRole){
return message.channel.send(‘He is not muted’);
}
})
and my thing is on hello-sq lite
pls help me

It just does not give the user the role