我正在尝试为我的机器人发出静音命令。该命令本身的工作原理,但甚至没有成员MANAGE_GUILD
许可,可以使用它(尽管机器人不会指派静音的作用,但它仍然会回复)。我需要这样做,以便机器人在用户没有"Missing Perms"
权限的情况下以MANAGE_GUILD
进行回复。
if (command === "mute") {
module.exports.run = async(bot, message, args) => {
if (!message.member.hasPermission("MANAGE_GUILD")) return message.channel.send("❌ Missing perms");
let tomute = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0]));
if (!tomute) return message.channel.send("❌ Cannot find user");
if (tomute.hasPermission("ADMINISTRATOR")) return message.channel.send("❌ Cannot mute admin");
let reason = args.slice(2).join(" ");
if (!reason) reason = "No reason provided";
let muterole = message.guild.roles.find(`name`, "muted");
//start of create role
if (!muterole) {
try {
muterole = await message.guild.createRole({
name: "muted",
color: "#000000",
permissions: []
})
message.guild.channels.forEach(async(channel, id) => {
await channel.overwritePermissions(muterole, {
SEND_MESSAGES: false,
ADD_REACTIONS: false
});
});
} catch (e) {
console.log(e.stack);
}
}
//end of create role
let mutetime = args[1];
if (!mutetime) return message.channel.send("❌ Specify mute time");
if (!tomute.roles.find("name", "muted")) {
message.channel.send(`✅ ${tomute.user} has been muted by ${message.author.tag} because: **${reason}**`).catch(O_o => {});
try {
await tomute.send(`You have been muted for **${mutetime}** because: **${reason}**`)
} catch (e) {
message.channel.send(`❌ failed to DM mute notification to ${tomute}`)
}
let muteembed = new Discord.RichEmbed()
.setDescription(`**USER MUTED**
Mute command executed by ${message.author}`)
.setColor(red)
.setFooter(`${message.author.tag}`)
.setTimestamp()
.addField("Muted User", tomute)
.addField("User ID", tomute.user.id)
.addField("Muted in", message.channel)
.addField("Duration", mutetime)
.addField("Reason", reason);
let incidentschannel = message.guild.channels.find(`name`, "action-log");
if (!incidentschannel) return message.channel.send("Please create a incidents channel first!");
incidentschannel.send(muteembed);
await (tomute.addRole(muterole.id));
setTimeout(function() {
tomute.removeRole(muterole.id);
let unmuteembed = new Discord.RichEmbed()
.setDescription(`**USER UNMUTED**
Unmute command executed by *Auto*`)
.setColor(green)
.setFooter(`Auto`)
.setTimestamp()
.addField("Unmuted User", tomute)
.addField("User ID", tomute.user.id)
.addField("Reason", "User was automatically unmuted because mute timer expired");
let incidentschannel = message.guild.channels.find(`name`, "action-log");
if (!incidentschannel) return message.channel.send("Please create a incidents channel first!");
incidentschannel.send(unmuteembed);
}, ms(mutetime));
} else {
message.channel.send(`❌ ${tomute} is already muted`)
}
//end of module
}
}