【发布时间】:2024-05-23 23:10:02
【问题描述】:
我想为我的 Discord 机器人编写一个ban 命令。我有这一行,机器人应该检查用户是否具有管理员权限。如果应该被禁止的用户拥有它们,则机器人不会禁止该用户并崩溃。当我尝试运行这个命令时,我得到了这个:
TypeError: Cannot read properties of undefined (reading 'has')
我不明白为什么。我问的没有人可以帮助我,我在网上找不到任何东西,所以我希望我能在这里找到帮助。
我的代码:
const discord = require('discord.js');
const { Permissions } = require('discord.js');
module.exports.run = async (Client, message, args) => {
if (!message.member.roles.cache.some(role => role.id == 589850931785498624)) {
return message.reply("You don't have the perms.");
}
const mention = message.mentions.users.first();
if (!mention) {
return message.reply('You need to tag a user!');
}
if (mention.permissions.has(Permissions.FLAGS.MANAGE_CHANNELS)) {
return message.reply("You can't ban an Administrator!")
}
//message.guild.members.ban(mention);
}
module.exports.help = {
name: "ban",
aliases: ["b"],
}
【问题讨论】:
标签: javascript node.js discord discord.js