尝试踢自己(机器人)时显示消息

时间:2021-01-11 20:43:44

标签: javascript node.js json discord discord.js

我正在命令中做出响应。我在尝试踢自己并工作时做出了回应,但现在我试图在踢机器人时做出回应,但它不起作用。

踢命令代码:

module.exports = {
    name: 'kick',
 aliases: ["k"],
    description: "kick a member",
 execute(message, Discord, client) {
    if(message.member.permissions.has("KICK_MEMBERS")){
        const member = message.mentions.members.first();
        let mention = message.mentions.members.first();
        if (message.mentions.members.size < 1) return message.reply('You must mention someone to kick them.').catch(console.error);
        if (message.mentions.members.first().id === message.author.id) return message.reply("I can't let you do that, self-harm is bad:facepalm:");

        if (message.mentions.members.id === client.member.id) return message.reply("You pleblord, how can you use a bot to kick itself?:joy:");

        if (message.mentions.members.first().id === "521311050193436682") return message.reply("You can't kick my Developer:wink:");
        if (reason.length < 1) reason = 'No reason supplied';

        if (!message.guild.member(user).kickable) return message.reply('I cannot kick that member');

        const embed = new Discord.MessageEmbed()
        .setColor(0x0000FF)
        .setTimestamp()
        .addField('Action:', 'Kick')
        .addField('User:', `${user.username}#${user.discriminator} (${user.id})`)
        .addField('Moderator:', `${message.author.username}#${message.author.discriminator}`)
        .addField('Reason', reason)
        .setFooter(`© Cryptonix X Mod Bot by ${customisation.ownername}`);

            if(user.bot) return;
          message.mentions.users.first().send({embed}).catch(e =>{
          if(e) return;
          });
             message.guild.member(user).kick();

         let logchannel = message.guild.channels.cache.find(x => x.name = 'logs');
            if  (!logchannel){
         message.channel.send({embed});
            }else{
         client.channels.cache.get(logchannel.id).send({embed});
          message.channel.send({embed});
         } 
            if(user.bot) return;
         message.mentions.users.first().send({embed}).catch(e =>{
            if(e) return ;
             });
         }

         else{
            let newEmbed = new MessageEmbed()
            .setColor('#e4e265')
            .setTitle('')
            .setURL('')
            .setDescription("Eeeh wait! You can't use that command <a:yepaa:797528125894295567>")
            .setImage('')
            .setFooter('');
    
            message.channel.send(newEmbed).then(r => r.delete({ timeout: 10000 }));
            }    
     }
};

这是我尝试在不和谐聊天中运行命令时遇到的错误

TypeError: Cannot read property 'member' of undefined
at Object.execute (C:\Users\ayman\Desktop\sharky music\commands\kick.js:15:56)

(kick.js:15:16 是尝试踢机器人时机器人响应的行)

2 个答案:

答案 0 :(得分:0)

如果你仔细观察,你已经定义了成员在 const member = message.mentions.members.first(); let mention = message.mentions.members.first();

!message.guild.member(user).kickable 从他们的代码中更改用户值后,您错过了更改 (user).kickable 返回的成员未定义,因为机器人找不到“用户”而不是“提及”

member 和mention 都是djs 中定义的值。所以我会说把它改成上面提到的东西。

你可以尝试: 删除const member = message.mentions.members.first();

改为:

const mentioned = message.mentions.members.first();

!message.guild.member(mentioned).kickable

if(mentioned.bot) return;

message.mentions.mentioned.first().send({embed}).catch(e =>{if(e) return;});

最后被 message.guild.member(mentioned).kick();

不知道它是否有效,但希望毕竟成员将被定义!


认为詹姆斯可能会得到回答,因为他已经在评论中发表了评论,但我只是在这里留下我的想法。如果我错了,请纠正我。

答案 1 :(得分:0)

<块引用>

if (message.mentions.members.id === client.member.id)

此 if 条件错误,因为 client 上不存在属性 member

您有两种方法可以解决您的问题:

  1. client.member.id替换client.user.id(id相同)

    // The other code from above this if statement
    if (message.mentions.members.id === client.user.id) return message.reply("You pleblord, how can you use a bot to kick itself?:joy:");
    // The following code
    
  2. client.member.id 替换 message.guild.me.id me 是来自客户端的 Guild#GuildMember 对象

    // The other code from above this if statement
    if (message.mentions.members.id === message.guild.me.id) return message.reply("You pleblord, how can you use a bot to kick itself?:joy:");
    // The following code