英文:
ERROR: Unhandled exception: Cannot read properties of undefined (reading 'FLAGS')
问题
"请修复它,这是一个 Discord 机器人的 antiswear.js 代码,很遗憾我不能修复它,我需要排除管理员在机器人的 antiswear 模块中,但它目前工作不正常。"
英文:
please fix it its a discord bot antiswear.js code its sad i cant fix it , i have to exclude admins from antiswear module of bot but its not working properly tho -
const { Permissions } = require('discord.js');
const badWords = require('@src/badwords.json');
const warnedMessages = new Set();
function checkMessage(message) {
const content = message.content.toLowerCase();
if (message.member && message.member.permissions && message.member.permissions.has(Permissions.FLAGS.ADMINISTRATOR, true)) {
return; // Skip moderation actions for administrators
}
</details>
# 答案1
**得分**: 1
你没有提供关于你所使用的版本的任何细节,所以我将假设是v14版本。如果下面的内容不适用,请告诉我,我将尽力研究适用于你的Discord.JS版本的信息。
根据[权限指南](https://discordjs.guide/popular-topics/permissions.html#checking-member-permissions),你需要稍微不同地使用`PermissionsBitField`类,如下所示:
第一行:
```js
// 你导入了错误的类。尝试使用PermissionsBitField代替!
const { PermissionsBitField } = require('discord.js');
第九行:
// 使用.Flags.Administrator属性而不是大写的相同属性
if (message.member && message.member.permissions && message.member.permissions.has(PermissionsBitField.Flags.Administrator, true)) {
PermissionsBitField文档和PermissionsFlagsBits文档
祝编码愉快!
英文:
You haven't provided any detail about what version you're on, so I'll assume v14. Let me know if the below doesn't work, and I'll do my best to research with your version of Discord.JS.
According to the Permissions Guide you need to use the PermissionsBitField
class slightly differently, like so:
Line one:
// You've imported the wrong class. Try PermissionsBitField instead!
const { PermissionsBitField } = require('discord.js');
Line nine:
// Use the .Flags.Administrator property instead of the same in upper case
if (message.member && message.member.permissions && message.member.permissions.has(PermissionsBitField.Flags.Administrator, true)) {
Docs for PermissionsBitField and Docs for PermissionsFlagsBits
Happy coding!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论