This snippet allows members with the KICK_MEMBERS permission (you can change this) to unmute a previously muted user in a server. To setup, just fill in your mute role ID on line 10 and go to the Slash Command Builder and make an unmute command with a user option (the user you want to unmute) and a string option (this is the reason), then to use it, just do /unmute USER REASON. This command will also send the unmuted user a DM that says where, why and by who they were unmuted in an embed. IF YOU NEED HELP SETTING UP, you can ping @Zeno in the Autocode Discord for support. Hope you enjoy!
// authenticates you with the API standard library
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
let isKICK_MEMBERS =
(context.params.event.member.permissions & (1 << 1)) === 1 << 1;
if (isKICK_MEMBERS) {
let userId = context.params.event.data.options[0].value;
let reason = context.params.event.data.options[1].value;
let roleId = `YOUR_MUTE_ROLE_ID_HERE`;
let result = await lib.discord.guilds['@0.1.0'].members.roles.destroy({
role_id: roleId, // required
user_id: userId, // required
guild_id: context.params.event.guild_id, // required
});
await lib.discord.channels['@0.2.0'].messages.create({
channel_id: context.params.event.channel_id,
content: `**<@${context.params.event.member.user.id}> - Successfully unmuted <@${userId}>!**`,
});
// make API request
// make API request
let guild = await lib.discord.guilds['@0.1.0'].retrieve({
guild_id: context.params.event.guild_id, // required
});
await lib.discord.users['@0.1.4'].dms.create({
recipient_id: `${userId}`,
content: '',
embed: {
type: 'rich',
title: `**You were unmuted!**`,
description: `
*In:* **${guild.name}**
*For:* **${reason}**
*Moderator:* **<@${context.params.event.member.user.id}>**`,
color: 131644,
},
});
} else {
await lib.discord.channels['@0.2.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `**<@${context.params.event.member.user.id}> You need the KICK_MEMBERS permission to use the Unmute command!**`,
});
}