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

Type error with permissionOverwrites #10450

Open
Fyrlex opened this issue Aug 19, 2024 · 8 comments · May be fixed by #10527 or #10528
Open

Type error with permissionOverwrites #10450

Fyrlex opened this issue Aug 19, 2024 · 8 comments · May be fixed by #10527 or #10528

Comments

@Fyrlex
Copy link

Fyrlex commented Aug 19, 2024

Which package is this bug report for?

discord.js

Issue description

With an existing guild text channel, an error is thrown when setting the permissionOverwrites with the required types.

Here is an example

const channel = await client.channels.fetch('some ID that exists as a text channel')

channel.permissionOverwrites
            .set([
              {
                id: client.user.id,
                allow: [
                  'SendMessages',
                ],
              },
            ]);

An error will be thrown

TypeError [InvalidType]: Supplied parameter is not a User nor a Role.

And the typings for this method I am using have id as a Snowflake
image

When using the client.user instead, there is no issue and the permissions are correctly changed.

Code sample

No response

Versions

  • discord.js 14.15.3
  • typescript 5.4.5
  • node 20.13.1

Issue priority

Low (slightly annoying)

Which partials do you have configured?

Not applicable

Which gateway intents are you subscribing to?

Not applicable

I have tested this issue on a development release

No response

@Renegade334
Copy link
Contributor

If you supply a snowflake as the id of an OverwriteData object and don't specify a type, then the user/role needs to be cached (otherwise d.js can't work out whether to set a role overwrite or a member overwrite).

If you don't know that the user/role is cached from context, then you can either pass the User/Role object directly as you mentioned, or supply a value for type.

channel.permissionOverwrites
            .set([
              {
                id: client.user.id,
                type: 'member',
                allow: [
                  'SendMessages',
                ],
              },
            ]);

@Jiralite
Copy link
Member

Jiralite commented Sep 4, 2024

That's correct. I believe it would be a good idea to adjust the error message here as it is misleading (the supplied parameter was indeed a user or a role). It should ideally mention that it was unable to resolve the type from the cache.

@Renegade334
Copy link
Contributor

I suppose the alternative (albeit breaking) approach would be to switch to using resolveId rather than resolve, and enforce overwrite.type as mandatory if overwrite.id is a string, to remove the need for cache lookups and thereby avoid cache-dependent error behaviour?

@Waheedsys
Copy link

can i work on this.

@didinele
Copy link
Member

Yes. If you know how to, feel free to open a pull request.

@Waheedsys
Copy link

sure, thank you @didinele

@baraich
Copy link

baraich commented Sep 30, 2024

@Waheedsys Hi, are you skilled to work the issue, if not let me take over. Thanks.

Waheedsys added a commit to Waheedsys/discord.js that referenced this issue Sep 30, 2024
@Waheedsys Waheedsys linked a pull request Sep 30, 2024 that will close this issue
Waheedsys added a commit to Waheedsys/discord.js that referenced this issue Oct 1, 2024
@Waheedsys
Copy link

Hey @Jiralite, could you please check if the ESLint error has been resolved? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants