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

RoleManager#fetch() may return null, but this is inconsistent #9260

Open
Astronautilus14 opened this issue Mar 21, 2023 · 2 comments
Open

RoleManager#fetch() may return null, but this is inconsistent #9260

Astronautilus14 opened this issue Mar 21, 2023 · 2 comments

Comments

@Astronautilus14
Copy link

Astronautilus14 commented Mar 21, 2023

Which package is this bug report for?

discord.js

Issue description

There is an inconsistency with fetching roles with this manager compared to the majority of other managers in discord.js.

Discord's API does not provide a way to fetch a single role... but discord.js does. discord.js fetches all roles and attempts to resolve a role and if it fails, the method returns null.

This is inconsistent as the other managers naturally throw an error. The inconsistency here may lead to an unsuspecting encounter. It is proposed that either a custom discord.js error is thrown instead of returning null or stop the resolving of a singular role.

Code sample

const role = await guild.roles.fetch(roleId); // If the roleId does not exist, role is null

const member = await guild.members.fetch(memberId); // If the memberId does not exist, an error is thrown

Package version

14.8.0

Node.js version

16.18.0

Operating system

Windows 10

Priority this issue should have

Low (slightly annoying)

Which partials do you have configured?

No Partials

Which gateway intents are you subscribing to?

Guilds, GuildMembers, GuildMessages, MessageContent

I have tested this issue on a development release

No

@monbrey
Copy link
Member

monbrey commented Mar 21, 2023

Roles does this because there isn't actually an API endpoint for fetching individual roles. It fetches all of the roles, tries to resolve the id, and can return null. We could make this throw an error in the next major.

Members though, no. Never returns undefined.
If memberId is defined but not a member of the guild, that fetch will throw an Unknown Member API error.
If memberId is undefined, it will fetch all members in the guild as if you didn't pass any parameters.

@Jiralite
Copy link
Member

I wouldn't call this a bug as there is no unexpected or unintended behaviour... return values are documented, so this shouldn't be a surprise.

@Jiralite Jiralite changed the title Inconsistency undefined vs null in fetch RoleManager#fetch() may return null, but this is inconsistent May 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants