有原因的踢命令

问题描述 投票:0回答:1

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

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

这里是我的代码:

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); 
}
          }
);
command bots discord discord.js
1个回答
0
投票

发布前应查看文档:

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

但是无论如何:

<Member>.kick(Reason),这只是您传递的字符串。

而且args看起来像一个数组,所以不能只在字符串中使用args,请尝试args.join(" ")。 (在message.channel.send("Kicked...")内部)

总而言之,这是更改:

所以mentionMember.kick() => mentionMember.kick(args.join(" "))

© www.soinside.com 2019 - 2024. All rights reserved.