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

Creating/Editing permission overwrites for uncached members throws "TypeError [INVALID_TYPE]: Supplied parameter is not a User nor a Role." #5493

Closed
almeidx opened this issue Apr 7, 2021 · 1 comment

Comments

@almeidx
Copy link
Member

almeidx commented Apr 7, 2021

Please describe the problem you are having in as much detail as possible:
If you try creating/editing a channel's permissionOverwrites for uncached members, the library throws TypeError [INVALID_TYPE]: Supplied parameter is not a User nor a Role.

The problem is here:

const userOrRole = guild.roles.resolve(overwrite.id) || guild.client.users.resolve(overwrite.id);

It should just default the overwrite type to member if a role is not resolved

Include a reproducible code sample here, if possible:

await guild.channels.create('cool', {
  permissionOverwrites: [{
    id: '', // include the id of an uncached member of your server
    allow: ['MANAGE_CHANNELS'] // this does not matter
  }]
})

// or

await channel.edit({
  permissionOverwrites: [{
    id: '', // include the id of an uncached member of your server
    allow: ['MANAGE_CHANNELS'] // this does not matter
  }]
})

Further details:

  • discord.js version: 12.5.3

  • Node.js version: 14.16.0

  • Operating system: Ubuntu 20.04

  • Priority this issue should have – please be realistic and elaborate if possible: medium

  • I have also tested the issue on latest master, commit hash: e848d25c86fcd4a11a7879f7dcd55d0bc93faa6d

@iShibi
Copy link
Contributor

iShibi commented Apr 17, 2021

The lib has to send type of the ovewrite to the API and thus it cannot default to anything arbitrarily. It tries to get this type by resolving the provided id, which isn't possible in case the structure that id belongs to isn't cached. This can be fixed by manually providing the type of the overwrite along with fields you have above, this will bypass the resolution of type part and thus no error will be thrown. The same technique is used in #5489 to fix a similiar problem.

@iCrawl iCrawl closed this as completed Jun 9, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants