用理由踢命令

时间:2020-05-28 19:32:50

标签: command bots discord discord.js

我创建了带有理由的kick命令,但它没有踢成员,我没有任何错误... 另外,为什么我发送命令时将其删除?

我试图自己修复它,但仍然无法正常工作。感谢您的帮助。

这是我的代码:

client.on('message', message => { 
  if(message.content.startsWith(prefix + "kick")) { 
     if(message.channel.type === 'DM') { 
    message.channel.send('This command can use only in guide'); 
    return; 
  }; 
  if(!message.member.hasPermission('KICK_MEMBERS')) { 
    const KickEmbed = new Discord.MessageEmbed()
    .setColor("YELLOW")
    .setAuthor(message.author.username)
    .setDescription("Sorry, but you don't have the permission to use the kick command.")
    message.channel.send(KickEmbed); 
    return; 
  }; 
  let mentionMember = message.mentions.members.first();
  if(!mentionMember) { 
    const ErrEmbed = new Discord.MessageEmbed()
    .setColor('YELLOW')
    .setAuthor(message.author.username)
    .setDescription('**Usage:** `y!kick <@user> or ID` You need to mention an user!')
    message.channel.send(ErrEmbed); 
                      return; 
                     };
        let args = message.content.slice(prefix.length).trim().split(/ +/g);
    if(!args.lenght) {
      const ReasonError = new Discord.MessageEmbed()
      .setColor('YELLOW')
      .setAuthor(message.author.username)
      .setDescription('Before kicking this member, you need to provide a reason of your kick.')
      message.channel.send(ReasonError)
      return;
    };
  let authorHighestRole = message.member.roles.highest.position; 
  let mentionHighestRole = mentionMember.roles.highest.position; 
  if(mentionHighestRole >= authorHighestRole) { 
    message.channel.send('You can`t kick members with equal or higher position'); 
    return; 
  }; 
  if(!mentionMember.kickable) {
    message.channel.send('I have no permissions to kick this user'); 
    return 
  }; 
  mentionMember.kick() 
    .then(() => message.channel.send(`Kicked ${mentionMember.tag} with reason: ${args}`)) 
    .catch(console.error); 
}
          }
);

1 个答案:

答案 0 :(得分:0)

发布前应先查看文档

https://discord.js.org/#/docs/main/stable/class/GuildMember?scrollTo=kick

但是无论如何:

@Recover,它只是您传入的字符串。

参数也看起来像一个数组,所以不能只在字符串中使用<Member>.kick(Reason),请尝试args。 (在args.join(" ")内)

总而言之,这里是更改:

所以message.channel.send("Kicked...") => mentionMember.kick()