gpt4 book ai didi

javascript - discord.js v13 permissions.has() 函数不工作(TypeError : Cannot read properties of undefined (reading 'has' ))

转载 作者:行者123 更新时间:2023-12-05 04:38:16 30 4
gpt4 key购买 nike

我想为我的 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"],
}

最佳答案

“TypeError: Cannot read properties of undefined (reading 'has')” 表示 mention.permissionsundefined。这是因为您的 mention 变量是 User并且只有 GuildMemberpermissions .

另一个错误是您尝试检查 role.id 是否等于数字/整数但是雪花(如 589850931785498624)should always be strings因为这些大于 MAX_SAFE_INTEGER .

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 mentionedMember = message.mentions.members.first();

if (!mentionedMember)
return message.reply('You need to tag a user!');

if (mentionedMember.permissions.has(Permissions.FLAGS.MANAGE_CHANNELS))
return message.reply("You can't ban an Administrator!");

message.guild.members.ban(mentionedMember);
};

关于javascript - discord.js v13 permissions.has() 函数不工作(TypeError : Cannot read properties of undefined (reading 'has' )),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70634214/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com