discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.36k stars 3.97k forks source link

Role created with default permissions when specified otherwise #3157

Closed ChrisTalman closed 5 years ago

ChrisTalman commented 5 years ago

Please describe the problem you are having in as much detail as possible: When creating a role, and explicitly specifying {permissions: 0}, the role seems to be created with default permissions, apparently ignoring the permissions option.

I'm not familiar with all the relevant module source code, but it seems as though the issue may be caused by this line:

if (data.permissions) data.permissions = Permissions.resolve(data.permissions);

0 is a falsy value, and so with that value, the condition will evaluate to false, even though a valid number was specified, and should be provided to the API.

Include a reproducible code sample here, if possible:

guild.createRole({permissions: 0});

Further details:

almostSouji commented 5 years ago

I can not reproduce this on 11.4.2 or 11.4-dev (neither on v12 if used correctly) The "reproducible" code sample creates a role without any permissions although i made sure the default role has permissions set.

The described behavior does occur however if the value null, not 0 is provided. This will indeed create a Role with the permissions taken from the default role @everyone

ChrisTalman commented 5 years ago

Interesting. I can't either. It's weird, because I've noticed this from time to time, across two different bots. In the case of the more recent bot, according to the commit history, its source code has always specified {permissions: 0}, and yet I recently discovered that all the roles that it had created in a guild had default permissions. The audit logs don't show any evidence that any member changed the permissions of the roles, and that would be unusual in the guild in question in any case. Quite strange.

SpaceEEC commented 5 years ago

This line of code is not causing issues, for the moment at least, as Permissions.resolve(0) will just return 0: https://github.com/discordjs/discord.js/blob/ebfbf20f07574b14f6425aaec2fd0288f3d7c872/src/util/Permissions.js#L191-L196 Although not the issue, not calling Permissions.resolve when a value is provided sounds like a bug to me.


Creating a role with (default) permissions does log those permissions in the audit log. Since you said there is nothing like that logged, your issue might be related to https://github.com/discordapp/discord-api-docs/issues/888? That issue is fixed now and it wasn't the default permissions though.

amishshah commented 5 years ago

Closing due to inactivity, if you can still reproduce this please re-open!

PSK1337 commented 4 years ago

it comes up when the user has a symbol in his name i just found it out myself testing the whole day