如何创建类似于我的静音命令(需要主持人或管理员权限)的取消静音命令?

时间:2018-07-24 09:09:00

标签: javascript node.js discord.js

我目前正在编码discord.js discord机器人,并且已经设法执行了基本的Kick,Ban和Warn命令(所有命令都记录到了一个通道),但是现在我正在使用Mute / Unmute命令。 ,我确实创建了Mutate命令,但是我现在遇到的问题是以类似的格式创建Unmute命令。

这是我的静音命令

if(command === "mute") {
let reason = args.slice(1).join(' ');
let user = message.mentions.users.first();
let logchannel = message.guild.channels.find('name', 'cgr420-logs');

if (!logchannel) return message.reply('I cannot find a logs channel');
if (!message.member.hasPermission("MUTE_MEMBERS")) return 
message.reply(":no_entry_sign: **Error:** You don't have the **Mute Members** 
permission!");
if (reason.length < 1) return message.reply('You must supply a reason for the 
mute.');
if (message.mentions.users.size < 1) return message.reply('You must mention 
someone to mute them.').catch(console.error);

if (!message.guild.member(user).bannable) return 
message.reply(`:no_entry_sign: I cannot mute that member`);
message.guild.member(user).ban();

const embed = new Discord.RichEmbed()
  .setColor(0xFF0000)
  .setTimestamp()
  .addField('Action:', 'Mute')
  .addField('User:', `${user.username}#${user.discriminator} (${user.id})`)
  .addField('Moderator:', 
  `${message.author.username}#${message.author.discriminator}`)
  .addField('Reason', reason);
  message.channel.send(`:hammer: Bippity boppity **MUTED**! I\'ve logged the 
  mute in the logs channel.`)
  return client.channels.get(logchannel.id).send({embed});
  };

我希望在正确的方向提供任何形式的帮助。

谢谢。

1 个答案:

答案 0 :(得分:0)

if(command === "unmute") {
let reason = args.slice(1).join(' ');
let user = message.mentions.users.first();
let logchannel = message.guild.channels.find('name', 'cgr420-logs');
let role = message.guild.roles.find('name', 'mute')
//CHANGE THIS ^^

if (!logchannel) return message.reply('I cannot find a logs channel');
if (!message.member.hasPermission("MUTE_MEMBERS")) return 
message.reply(":no_entry_sign: **Error:** You don't have the **Mute Members** 
permission!");
if (reason.length < 1) return message.reply('You must supply a reason for the mute.');
if (message.mentions.users.size < 1) return message.reply('You must mention 
someone to mute them.').catch(console.error);

if (!message.guild.member(user).roles.has(role)) return message.reply(`:no_entry_sign: I cannot unmute that member`);
message.guild.member(user).removeRole(role);

const embed = new Discord.RichEmbed()
  .setColor("0xFF0000")
  .setTimestamp()
  .addField('Action:', 'Unmute')
  .addField('User:', `${user.tag} (${user.id})`)
  .addField('Moderator:', 
  `${message.author.tag}`)
  .addField('Reason', reason);
  message.channel.send(`:hammer: Bippity boppity **UNMUTED**! I\'ve logged the 
  unmute in the logs channel.`)
  return logchannel.send(embed);
  };

您不必执行client.channels.get(logchannel.id).send(),只需执行logchannel.send()

我看到您已禁止必须“取消静音”的成员,我创建了一个变量mute,它找到一个名为“静音”的角色,您可以将其更改为你想。该命令从成员中删除mute角色。