ERROR: 未处理的异常:无法读取未定义的属性(读取’FLAGS’)

huangapple go评论73阅读模式
英文:

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&#39;ve imported the wrong class. Try PermissionsBitField instead!
const { PermissionsBitField } = require(&#39;discord.js&#39;);

Line nine:

// Use the .Flags.Administrator property instead of the same in upper case
  if (message.member &amp;&amp; message.member.permissions &amp;&amp; message.member.permissions.has(PermissionsBitField.Flags.Administrator, true)) {

Docs for PermissionsBitField and Docs for PermissionsFlagsBits

Happy coding!

huangapple
  • 本文由 发表于 2023年7月6日 17:46:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76627544.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定