简体   繁体   English

discord.js UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'kickable' of undefined

[英]discord.js UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'kickable' of undefined

Yesterday I could run this scrip.昨天我可以运行这个脚本。 Today I get the error今天我得到了错误

(node:29568) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'kickable' of undefined (节点:29568)UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“可踢”

I'm running version "discord.js": 12.1.1 - I hope someone can spot what I'm doing wrong here... because it's drive me nuts.我正在运行版本“discord.js”:12.1.1 - 我希望有人能发现我在这里做错了什么......因为它让我发疯。

Bellow you can find my kickuser.js - script + my index.js script -> https://pastebin.com/7tLkuU5p下面你可以找到我的 kickuser.js - 脚本 + 我的 index.js 脚本 -> https://pastebin.com/7tLkuU5p

const Discord = require("discord.js");

module.exports.run = async (bot, message, args) => {

    if (message.member.hasPermission("KICK_MEMBERS")) {

        if (!message.mentions.users) return message.reply('You must tag 1 user.');

        else {

            const channel = message.guild.channels.cache.get(696692048543088691);
            const member = message.mentions.members.first();
            let reason = message.content.split(" ").slice(2).join(' ');

            if (member.kickable == false) return message.channel.send("That user cannot be kicked!")

            else {

                if (!reason) reason = (`No reason provided.`);

                await member.send(`You have been kicked from **${message.guild.name}** with the reason: **${reason}**`)
                    .catch(err => message.channel.send(`⚠ Unable to contact **${member}**.`));

                await member.kick(reason);

                const kickEmbed = new MessageEmbed()
                    .setAuthor(member.user.tag, member.user())
                    .setThumbnail(member.user.avatarURL())
                    .setColor("#ee0000")
                    .setTimestamp()
                    .addField("Kicked By", message.author.tag)
                    .addField("Reason", reason);

                await channel.send(kickEmbed);

                console.log(`${message.author.tag} kicked ${member.user.tag} from '${message.guild.name}' with the reason: '${reason}'.`);

            }
        }
    } else {
        message.channel.send("You do not have permission to use kick.");
        return;
    }
}


module.exports.help = {
    name: "kickuser"
}

I hope someone can help me.我希望有一个人可以帮助我。 Thanks in advance.提前致谢。

message.mentions.users always evaluates to true because it is an object, and to check if the message has any mentions, you can do: message.mentions.users总是评估为 true,因为它是 object,并且要检查消息是否有任何提及,您可以执行以下操作:

    if(!message.mentions.members.first()) return message.reply('You must tag 1 user.');

instead of:代替:

    if(!message.mentions.users) ...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Discord.JS UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“startsWith” - Discord.JS UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'startsWith' of undefined Discord.js | UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“部分” - Discord.js | UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'partial' of undefined UnhandledPromiseRejectionWarning:TypeError:无法读取未定义 Discord.JS 的属性“forEach” - UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'forEach' of undefined Discord.JS Node.js Discord.js UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“calculatedPosition” - Node.js Discord.js UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'calculatedPosition' of undefined (node:4468) UnhandledPromiseRejectionWarning: TypeError: 无法读取未定义 Discord.js 的属性“公会” - (node:4468) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'guild' of undefined Discord.js discord.js错误TypeError:无法读取未定义的属性“ voiceChannel” - discord.js Error TypeError: Cannot read property 'voiceChannel' of undefined Discord.JS:TypeError:无法读取未定义的属性“角色” - Discord.JS:TypeError: Cannot read property 'roles' of undefined discord.js TypeError:无法读取未定义的属性“名称” - discord.js TypeError: Cannot read property 'name' of undefined 类型错误:无法读取 discord.js 中未定义的属性“执行” - TypeError: Cannot read property 'execute' of undefined in discord.js “ TypeError:无法读取未定义的属性'push'” discord.js - “TypeError: Cannot read property 'push' of undefined” discord.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM