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

Incorrect resolve of bits in BitField #9247

Closed
Syjalo opened this issue Mar 19, 2023 · 0 comments · Fixed by #9262
Closed

Incorrect resolve of bits in BitField #9247

Syjalo opened this issue Mar 19, 2023 · 0 comments · Fixed by #9262

Comments

@Syjalo
Copy link
Contributor

Syjalo commented Mar 19, 2023

Which package is this bug report for?

discord.js

Issue description

Due to the use of enums flags have reverse values. If we use string bit filed the bit resolves to the key instead of the value.

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

Code sample

import { GuildMemberFlagsBitField } from 'discord.js';

const permission1 = new GuildMemberFlagsBitField('1');
const permission2 = new GuildMemberFlagsBitField('2');
const permission3 = new GuildMemberFlagsBitField('3');

console.log(permission1.bitfield); // 'DidRejoin'
console.log(permission2.bitfield); // 'CompletedOnboarding'
console.log(permission3.bitfield); // 3
console.log(GuildMemberFlagsBitField.Flags);
/**
{
  '1': 'DidRejoin',
  '2': 'CompletedOnboarding',
  '4': 'BypassesVerification',
  '8': 'StartedOnboarding',
  DidRejoin: 1,
  CompletedOnboarding: 2,
  BypassesVerification: 4,
  StartedOnboarding: 8
}
**/

Package version

14.8.0

Node.js version

18.15.0

Operating system

Win 11

Priority this issue should have

Medium (should be fixed soon)

Which partials do you have configured?

No Partials

Which gateway intents are you subscribing to?

No Intents

I have tested this issue on a development release

No response

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.

2 participants