{"size": 1155, "ext": "js", "max_stars_repo_path": "commands/moderation/unmute.js", "max_stars_repo_name": "F7ASH/AR-Bot-By-FSX", "max_stars_repo_stars_event_min_datetime": "2020-12-06T22:56:22.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-02T16:01:30.000Z", "max_issues_repo_path": "commands/moderation/unmute.js", "max_issues_repo_name": "F7ASH/AR-Bot-By-FSX", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "commands/moderation/unmute.js", "max_forks_repo_name": "F7ASH/AR-Bot-By-FSX", "max_forks_repo_forks_event_min_datetime": "2021-04-20T16:43:56.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-21T01:45:41.000Z"}
{"max_stars_count": 9, "max_issues_count": null, "max_forks_count": 6, "avg_line_length": 24.0625, "max_line_length": 59, "alphanum_fraction": 0.5454545455}
const { MessageEmbed } = require("discord.js");
const muteSchema = require("../../models/muteSchema");

module.exports = {
  name: "unmute",
  commands: ["unmute"],
  aliases: ["um"],
  description: "unMuting a User",
  minArgs: 1,
  category: "moderation",
  cooldown: "5s",
  expectedArgs: "{PREFIX}mute [<@ user-id> or <user-tag>]",
  callback: async ({ message, args }) => {
    const { guild } = message;
    let id = "";
    const target = message.mentions.users.first();
    if (target) {
      id = target.id;
    } else {
      id = args[0];
    }
    const results = await muteSchema.updateOne(
      {
        guildId: guild.id,
        userId: id,
        current: true,
      },
      {
        current: false,
      }
    );
    // console.log("RESULT:", results);

    if (results.nModified === 1) {
      const role = guild.roles.cache.find((role) => {
        return role.name === "Muted";
      });
      if (role) {
        const guildMember = guild.members.cache.get(id);
        guildMember.roles.remove(role);
      }
      message.reply(`Unmuted`);
    } else {
      message.reply("The Mentioned User is not muted");
    }
  },
};
