Mute Command With A Time

I have a ban command, but i’d like it so the user can do it for a specific time. I just have code for it to mute them member, but the person would need to use an unmute command.

How ould I make the code for muting a member for, say 10 minutes?

module.exports = {
  name: "ban",
  description: "Ban those pesky users!",
  async execute(message, args) {
    let {RichEmbed} = require("discord.js");
    
    if(!message.member.hasPermissions(["BAN_MEMBERS", "ADMINISTRATOR"])) return message.channel.send("You don't have sufficient permissions to run this command");
    
    let banMember = message.mentions.members.first() || message.guild.members.get(args[0]);
    
    if(!banMember) return message.channel.send("You did not provide a user to ban. Please provide a user to ban");
    
    let reason = args.slice(1).join(" ");
    if(!reason) reason = "No reason provided";
    
    if(!message.guild.me.hasPermission(["BAN_MEMBERS", "ADMINISTRATOR"])) return message.channel.send("I do not have sufficient permissions to ban this user. Please try again.");
    
    banMember.send(`You have permanently been banned from ${message.guild.name} because: ${reason}.`).then(message.guild.ban(banMember)).catch(err => console.log(err));
    
    message.channel.send(`**${banMember.user.tag}** has be successfully banned`).then(m => m.delete(5000));
    
    let banEmbed = new RichEmbed()
      .setColor("#FF0000")
      .addField("Moderation Action", "ban")
      .addField("Banned Member", banMember.user.username)
      .addField("Moderator", message.author.username)
      .addField("Reason", reason)
      .addField("Date:", message.createdAt.toLocaleAString());
    
    let modChannel = message.guild.channels.find(channel => channel.name === "mod-log");
    
    modChannel.send(banEmbed);
  },
};

How does it work?

Please avoid posting in old threads. You can find tutorials for discord.js commands in many places on the internet (ie. YouTube, GitHub).

1 Like