[英]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.