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

fix(GuildChannel): overload permissionsFor and BaseManager#resolve[id] #5260

Merged

Conversation

kyranet
Copy link
Member

@kyranet kyranet commented Jan 25, 2021

Please describe the changes this PR makes and why it should be merged:

The behaviour of GuildChannel#permissionsFor, is that if it's able to resolve the data, it will always return permissions (since the private methods memberPermissions and rolePermissions never return null):

permissionsFor(memberOrRole) {
const member = this.guild.members.resolve(memberOrRole);
if (member) return this.memberPermissions(member);
const role = this.guild.roles.resolve(memberOrRole);
if (role) return this.rolePermissions(role);
return null;
}

For data to be resolvable, it expects either an instance or a string:

resolve(idOrInstance) {
if (idOrInstance instanceof this.holds) return idOrInstance;
if (typeof idOrInstance === 'string') return this.cache.get(idOrInstance) || null;
return null;
}

If an instance is provided, it will always return the instance itself, therefore, when passing a value that matches Holds, the type return should always be Holds as well.

When passing a string, the return can be nullable, so this is excluded from the non-nullable return.

Things change when GuildMemberManager#resolve is used, as it's overloaded to support more types (specifically User instances), which resolves an ID and then tries to get the GuildMember from it, that is why I am not using Exclude<GuildMemberResolvable | RoleResolvable, string>.

resolve(member) {
const memberResolvable = super.resolve(member);
if (memberResolvable) return memberResolvable;
const userResolvable = this.client.users.resolveID(member);
if (userResolvable) return super.resolve(userResolvable);
return null;
}

Status

  • Code changes have been tested against the Discord API, or there are no code changes
  • I know how to update typings and have done so, or typings don't need updating

Semantic versioning classification:

  • This PR changes the library's interface (methods or parameters added)
    • This PR includes breaking changes (methods removed or renamed, parameters moved or removed)
  • This PR only includes non-code changes, like changes to documentation, README, etc.

@kyranet kyranet mentioned this pull request Jan 25, 2021
1 task
@kyranet kyranet linked an issue Jan 25, 2021 that may be closed by this pull request
1 task
@iCrawl iCrawl merged commit 41bd6c2 into discordjs:master Jan 27, 2021
@iCrawl iCrawl added this to the Version 13 milestone Jun 27, 2021
@kyranet kyranet deleted the fix/make-permissions-and-resolve-more-accurate branch July 5, 2021 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Channel permissionsFor can be null
4 participants