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
Medivh 115 points

                                    // 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');

3.75 (4 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
mute command discord/js mute user discord.js mute member discord js mute member command discord.js v12 discord js mute a user in voice channel how to mute a user in discord.js how to mute some discord.js how to mute members discord js command how to mute members discord js mute discord by id discord js mute command discord.js id discord.js mute member discord mute members discord.js mute command with embedded messages discord js mute in discord js mute and unmute discord js mute discord bot js how to mute someone discord bot js discord.js mute members create mute command discord.js server mute discord.js mute member through discord js mute command for discord js how to mute a bot discord.js discord.js mute someone how to server mute someone in discord with discord.js discordjs mute comamnd how to make mute command discord.js discord.js mute someone in just one channel mute code discord.js mute the bot discord js discord.js mute user mute command and with ms and reason in discord.js server mute discord discord.js mute someone on discord discord.js mute bot discord js server mute command discord.js mute reason discord.js mute command discordjs discord source code to mute a member from args how to mute discord discord mute command how to mute in a vc discord js how to mute discord js script mute discord js commande de mute discord js discordjs temporary mute command mute discords.js mute person who sent message discord.js discord.js mute script discord. mute script discord js how to mute a user comando mute discord mute command discord code .mute @user discord.js mute someone discord.js MUTE_MEMBER discord.js discord js mute discord js how to mute user Mute Command For Discord.JS Bot Mute script bot discord discord bot with mute command discord.js mtempmute and mute discord.js mute and tempmute discord.js mute command code 2020 temp mute command discord.js discord mute bot v12 discord.js mute command handdler discordjs how to make message silent discord mute command code how to use mute someone discord.js discord.js muterole mute discord.js ms discord.js is user muted discord.js user is muted? discord bot javascript mute command discord js mute by id mute discord.js discord.js mute commmande how to make a mute command discord.js mute command discord js mute command discord.js discord.js mute in chat code discord.js mute in chat code copy discord.js mute code copy discord.js mute command v11 mute member discord.js discord js user mute update js discord bot mute how to mute a user discord nodejs how to mute someone in discord js discord js how to mute someone mute discord.js v12 discord.js mute discord bot mute user js mute command with time discord.js 12 mute command discord.js 2020 create mute role discord js mute role discord js discord js mute a user discord js 12 mute command mute discord js mute user discord js discord.js mute role auto Discord js mute command example discord.js mute command v12 discord js mute command discord mute js js discord mute bot discord.js mute bot discord.js temp mute command discord js make mute role mute command discord.js v12 mute and unmute command discord.js create mute role if not made discord.js temp mute mute ms discord.js discord.js mutes Discord js, chat mute command discord.js mute command mute command discord.js v12 with databse how to mute discord.js how to mute someone discord.js
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source