how to mute someone discord.js
const Discord = require('discord.js');
const client = new Discord.Client();
const prefix = "!";
const token = ""; // Fill in your token
client.on("message", msg => {
msg.content.startsWith(prefix + "mute") {
// Variables
var muteRole = msg.guild.roles.find(role => role.name.toLowerCase().includes("muted"));
var muteChannel = msg.guild.channels.find(channel => channel.name.includes("modlogs"));
var muteUser = msg.mentions.members.first();
var muteReason = msg.content.slice(prefix.length + 27);
// Conditions
if (!msg.member.hasPermission("MANAGE_MESSAGES")) return msg.channel.send("You don't have the permissions");
if (!muteUser) return msg.channel.send("You have to mention a valid member");
if (!muteChannel) return msg.channel.send("There's no channel called modlogs");
if (!muteRole) return msg.channel.send("There's no role called muted");
if (!msg.guild.member(client.user.id).hasPermission("MANAGE_ROLES")) return msg.channel.send("I Don't have permissions");
if (!muteReason) muteReason = "No reason given";
// Embed
var muteEmbed = new Discord.RichEmbed()
.setTitle("Mute")
.addField("Muted user", muteUser)
.addField("Reason", muteReason)
.setFooter(`Muted by ${msg.author.tag}`)
.setTimestamp();
//Mute
muteUser.addRole(muteRole);
msg.channel.send(`${muteUser} has been muted`);
muteChannel.send(muteEmbed);
}
})
3.75
4
// get the role by id:
const mutedRole = message.guild.roles.cache.get('<Muted Role ID>');
// or, if you can't get the id:
const mutedRole = message.guild.roles.cache.find(
(role) => role.name === 'Muted'
);
// if there is no `Muted` role, send an error
if (!mutedRole)
return message.channel.send('There is no Muted role on this server');
Thank you!
4
0
Are there any code examples left?
New code examples in category Other
-
Other 2023-03-27 22:50:10 how to select the whole line in vscode with keyboard shortcut
-
Other 2022-03-27 22:45:24 income of a web developer
-
Other 2022-03-27 22:35:01 \pyrcc_main.py: File does not exist 'resources.qrc'
-
Other 2022-03-27 22:30:45 rick roll embed code
-
Other 2022-03-27 22:20:08 Circuit_04_Potentiometer
-
Other 2022-03-27 22:20:05 iterative power
-
Other 2022-03-27 22:15:11 flutter run all
-
Other 2022-03-27 22:10:05 when is karlson release
-
Other 2022-03-27 22:10:02 wp .htaccess example
-
Other 2022-03-27 22:00:08 bash pause in file read line by line