discord.js UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“可踢”

时间:2020-04-09 15:49:05

标签: javascript error-handling typeerror discord discord.js

昨天我可以运行此脚本。 今天我得到了错误

(节点:29568)UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“可踢”

我正在运行“ discord.js”版本:12.1.1-我希望有人能在这里发现我做错的事情...,因为它使我发疯。

下面您可以找到我的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"
}

我希望有人能帮助我。 预先感谢。

1 个答案:

答案 0 :(得分:1)

message.mentions.users始终为true,因为它是一个对象,要检查消息是否有提及,可以执行以下操作:

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

代替:

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