discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.33k stars 3.97k forks source link

BitField#toArray() returning the bitfield with the bitfield name #9350

Closed joeyk710 closed 1 year ago

joeyk710 commented 1 year ago

Which package is this bug report for?

discord.js

Issue description

Here is the result I got on v14.9.0 accessing UserFlagsBitField#toArray()

image

This is the temporary workaround I made so the bitfield is removed from the array:

const flagStrings = message.author.flags.toArray().map((flagName) => flagName);

const flagSplice = flagStrings.splice(0, flagStrings.length / 2, ...flagStrings.splice(0, flagStrings.length / 2).reverse());
image

Code sample

Access the flags from a user with UserFlagsBitField#toArray() and the client's intents with IntentsBitField#toArray().

Tested code:
- message.author.flags.toArray()
- message.client.options.intents.toArray()

Package version

v14.9.0

Node.js version

v18.5.0

Operating system

Linux arm64

Priority this issue should have

Medium (should be fixed soon)

Which partials do you have configured?

User, Channel, Message

Which gateway intents are you subscribing to?

Guilds, GuildMembers, GuildModeration, GuildPresences, GuildMessages, MessageContent

I have tested this issue on a development release

No response

jaw0r3k commented 1 year ago

For me the issue comes from iterating over an enumeration https://github.com/discordjs/discord.js/blob/b2eec5f9fcf37ebb3b7f87a67a6ee3160c182183/packages/discord.js/src/util/BitField.js#L142

As it has both: names and bits in it