RangeError [BITFIELD_INVALID]:无效的位域标志或数字 [英] RangeError [BITFIELD_INVALID]: Invalid bitfield flag or number

查看:17
本文介绍了RangeError [BITFIELD_INVALID]:无效的位域标志或数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我正在处理我的静音命令,我想出了这个错误:

Hello I am working on my mute command and I came up with this erorr:

RangeError [BITFIELD_INVALID]: Invalid bitfield flag or number.
at Function.resolve (/app/node_modules/discord.js/src/util/BitField.js:150:19)
     at /app/node_modules/discord.js/src/util/BitField.js:148:54
   at Array.map (<anonymous>)
     at Function.resolve (/app/node_modules/discord.js/src/util/BitField.js:148:40)
     at RoleManager.create (/app/node_modules/discord.js/src/managers/RoleManager.js:112:58)
    at Client.<anonymous> (/app/index.js:586:41)
    at Client.emit (events.js:327:22)
    at MessageCreateAction.handle (/app/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
   at Object.module.exports [as MESSAGE_CREATE] (/app/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (/app/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)

我想为我的静音命令设置一个静音角色这是我的命令:

I want to make a mute role for my mute command here is my command:

 message.guild.roles.create({
                        data: {
                          name: 'muted',
                          color: '#ff0000',
                          permissions: [
                              "SEND_MESSAGES" === false,
                              "ADD_REACTIONS" === false

                          ]
                        },
                        reason: 'to mute people',
                      })
                        .catch(console.error);
                } catch (e) {
                    console.log(e.stack);
                }
            } return message.channel.send('Cant')

我不知道如何解决它,请帮助我

I don't quite know how to fix it please help me

推荐答案

我今天偶然发现了这个老问题,虽然我有点晚了,但 Androz2091 发布的当前主要答案是不正确的.

I stumbled onto this old question today, and though I'm quite a bit late, the current primary answer posted by Androz2091 is incorrect.

您不能使用数组作为权限值(它必须是一个对象):

You can't use an array for the permissions value (it must be an object):

这完全是错误的.在从 v11 到 v13 的任何版本的 discord.js 中,都没有权限值来创建一个角色,即该答案呈现的形式的对象文字.权限值必须是 PermissionResolvable.PermissionResolvable 可以是字符串,例如 SEND_MESSAGES",也可以是此类字符串的数组.查看文档.

This is completely false. In no version of discord.js from v11 to v13 was the permissions value for creating a role an object literal in the form presented by that answer. The permissions value must be a PermissionResolvable. A PermissionResolvable can be a string such as "SEND_MESSAGES", or it can be an array of such strings. Review the docs.

至于 OP 究竟出了什么问题,请注意他们是如何指定权限字符串的:

As for what the OP actually got wrong, notice how they specified their permission strings:

permissions: [
    "SEND_MESSAGES" === false,
    "ADD_REACTIONS" === false
]

这是不正确的.这与执行 permissions: [ false, false ] 相同.显然 false 不是权限,这就是您收到无效位域标志错误的原因.

That is incorrect. That's the same thing as doing permissions: [ false, false ]. Obviously false is not a permission, which is why you are getting the invalid bitfield flag error.

创建角色时权限的工作方式并非如此.如果您查看公会的角色权限,您会发现每个权限都有两种状态:启​​用或禁用.guild.roles.create() 中权限值的工作方式是,它启用任何指定的权限并禁用所有其他权限.这意味着,如果您希望为您的 Muted 角色禁用 SEND_MESSAGESADD_REACTIONS,您只需不将它们包含在权限数组中.

That is not how permissions work when creating roles. If you look at your guild's role permissions, you'll see that each permission has two states: enabled or disabled. The way the permissions value works in guild.roles.create() is, it enables any permissions that are specified and disables ALL other permissions. That means, if you want SEND_MESSAGES and ADD_REACTIONS disabled for your Muted role, you simply need to not include them in the permissions array.

相反,包括被静音的用户应该拥有的任何权限.例如,如果他们应该能够观看频道,请给他们VIEW_CHANNEL.这是一个示例解决方案:

Instead, include whatever permissions the muted users are supposed to have. For example, if they should be able to view channels, give them VIEW_CHANNEL. Here is an example solution:

permissions: [
    "VIEW_CHANNEL",
    "READ_MESSAGE_HISTORY"
]

这对于静音角色应该很有效.请注意,discord.js v12 和 v13 的权限以这种方式工作的方式仍然相同,但是您创建角色本身的方式在版本之间发生了一些变化.但是,这个解决方案应该仍然适用于这两个版本.

That should work pretty well for a Muted role. Note that how permissions work in this way is still the same for both discord.js v12 and v13, but the way in which you create roles itself has changed a little bit between the versions. However, this solution should still be applicable to both versions.

这篇关于RangeError [BITFIELD_INVALID]:无效的位域标志或数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆