Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
joeyk710 opened this issue Apr 8, 2023 · 1 comment · Fixed by #9357
Closed

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

joeyk710 opened this issue Apr 8, 2023 · 1 comment · Fixed by #9357

Comments

@joeyk710
Copy link

joeyk710 commented Apr 8, 2023

Which package is this bug report for?

discord.js

Issue description

  • When accessing the method BitField#toArray(), this is suppose to return only the Array of BitField names based on the bit given. The actual result returns the bitfield itself as a string as well as the bitfield name, which is the expected result.

  • The PR fix: resolving string bitfield #9262, and the issue Incorrect resolve of bits in BitField #9247 both attempt to address this issue, but does not occur on v14.8.0 and is shown below. I am unsure why this change was necessary since I was not experiencing these issues at all in previous versions.

    if (typeof bit === 'string') {
    if (this.Flags[bit] !== undefined) return this.Flags[bit];
    if (!isNaN(bit)) return typeof DefaultBit === 'bigint' ? BigInt(bit) : Number(bit);
    }

  • On v14.9.0, this has line 167 moved to line 168 (shown below), which is indeed causing an issue with the bitfield and bitfield name showing together.

    if (typeof bit === 'string') {
    if (!isNaN(bit)) return typeof DefaultBit === 'bigint' ? BigInt(bit) : Number(bit);
    if (this.Flags[bit] !== undefined) return this.Flags[bit];
    }

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

  • It would appear that PermissionsBitField#toArray() does not have this issue from testing, but other extended BitField classes do. This does show the expected result with the permission bitfield name only.

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
Copy link
Contributor

jaw0r3k commented Apr 8, 2023

For me the issue comes from iterating over an enumeration

for (const bitName of Object.keys(this.constructor.Flags)) {

As it has both: names and bits in it

@kodiakhq kodiakhq bot closed this as completed in #9357 Apr 28, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants