简体   繁体   中英

I'm having trouble with discord.js

i'm want add some permissions for using adminstator commands like ban, kick etc. When im add that commands i can't using kick command and when im tryna use ban command i get a output like that: "@xxx, you can't kick a member in this guild."

  if (message.author.bot) return;
  // This is where we'll put our code.
  if (message.content.indexOf(prefix) !== 0) return;
 
  const args = message.content.slice(prefix.length).trim().split(/ +/g);
  const command = args.shift().toLowerCase();
 
  if(command === 'kick') {
    const user = message.guild.member(message.author);
    if (user.hasPermission(['KICK_MEMBERS'])) {
    let reason = args.join(" ");
    const member = message.guild.member(etiketlenmiskisi);
    message.channel.send(`${message.author} took her/his kickhammer!`);
    message.channel.send('https://tenor.com/view/sao-liz-lisbeth-anime-ban-gif-14368031');
    member.kick(reason);
    message.channel.send(`${etiketlenmiskisi} kicked successfully.`);
  }} else {
    message.channel.send(`${message.author}, you can't kick a member in this guild.`);
  }

});

client.on("message", message => {
  if (message.author.bot) return;
  // This is where we'll put our code.
  if (message.content.indexOf(prefix) !== 0) return;
 
  const args = message.content.slice(prefix.length).trim().split(/ +/g);
  const command = args.shift().toLowerCase();
 
  if(command === 'ban') {
    const user = message.guild.member(message.author);
    if (user.hasPermission(['BAN_MEMBERS'])) {
    const etiketlenmiskisi = message.mentions.users.first();
    let reason = args.join(" ");
    const member = message.guild.member(etiketlenmiskisi);
    message.channel.send(`${message.author} took her/his banhammer!`);
    message.channel.send('https://tenor.com/view/sao-liz-lisbeth-anime-ban-gif-14368031');
    member.ban(reason);
    message.channel.send(`${etiketlenmiskisi} banned successfully.`);
  }} else {
    message.channel.send(`${message.author}, you can't ban a member in this guild.`);
  }

});

It's in an else statement the "you can't kick". It should be an else if. That should fix the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM