-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Add GuildChannel.deleteOverwrite() #5234
Conversation
I see no benefit in this over https://discord.js.org/#/docs/main/stable/class/PermissionOverwrites?scrollTo=delete. Deletions in Discord.js always happen on the structure itself, not the corresponding manager. |
Then why did we add https://discord.js.org/#/docs/main/stable/class/MessageManager?scrollTo=delete recently? |
MessageManager#delete can operate on uncached messages. |
Co-authored-by: anandre <38661761+anandre@users.noreply.github.com>
It doesn’t make any sense to have methods inside GuildChannel to create and update permission overwrites (which do exactly the same) and not have one to delete. The thing you linked only works on specific situations and, for example, didn’t work for what I was looking for, and this did, so I think it would be useful and would make sense |
* .catch(console.error); | ||
*/ | ||
deleteOverwrite(userOrRole) { | ||
userOrRole = this.guild.roles.resolve(userOrRole) || this.client.users.resolve(userOrRole); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will throw for valid but uncached users. Ideally this function should only make an API call and let the API decide whether the role/user exists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed it will, the other methods which this is likely based on do this as well, there is an open discussion about this #5230
I think if this is being added, in this instance it should definitely be passed directly to discords API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I simply followed the way it is currently handled in other methods, although I definitely agree it should use an ID instead of the user or role. Even then I’m not sure if I should change that before your changes get accepted and committed since that would create inconsistencies
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I linked is simply a discussion for how we should handle this, it is not a PR yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I know, but you proposed changes that weren't accepted yet so it's not worth changing it here since it could create inconsistencies if those changes are never implementes
Can you give an example for when it doesn't work? |
This is a misconception on your end.
GuildChannel#permissionOverwrites is not a manager. There is no data that may need to be fetched and can be uncached (managing that data is the sole purpose of managers) Of course, it makes sense to have a method to create and update overwrites, and since they can't be on the Manager (since it just doesn't exist in the first place) they will have to be on GuildChannel. Delete however makes no sense to have on the GuildChannel class, as there is - again - no need to ever fetch overwrites, which you could save an API call for by introducing this method; you get them with the channel, always. To delete an overwrite - as is the case with other structures that are not handled by managers - you can retrieve the overwrite from GuildChannel#permissionOverwrites and call delete on the resulting structure const ov = message.channel.permissionOverwrites.get("<User or Role ID>"):
ov.delete()
There is no case where this would not work. Even with intents GUILD_CHANNEL_UPDATE, GUILD_CHANNEL_CREATE, GUILD_CREATE are all categorized under the GUILD intent.
They do not.
|
Tried to delete the permission overwrite for role with ID 768435276191891456 on channel 613015467984158742 and it didn't work guild.channels.cache.get("613015467984158742").permissionOverwrites.delete(guild.roles.cache.find(r => r.id === "768435276191891456"))``` |
I don't want to delete the permission overwrites for that channel, I wanna delete the permission overwrites for a specific role/user on that channel.
Refer to my comment above |
Yes, and I instructed how to do that above. Which you choose to ignore and instead demonstrate your misunderstanding once again.
I can't refer to something that's a misunderstanding of how things work on your end. You are demonstrating the wrong usage of the method instead of listening to what I was saying. again. the way to do this is to retrieve the PermissionOverwrite instance from the
|
Alright, my bad, I missed the user or role id part, I was on mobile, no need to be so aggressive about it jeez
Alright, I understand all of that. Now can you explain what would be the issue with merging this? |
Calling delete on the structure itself is a coherent approach across all of the library. This adds no functionality (the exception brought up by Mark above is useful due to not needing to fetch uncached structures and does not apply here) but instead code duplication. After internal discussion to make sure I haven't missed anything and this approach is not preferable to the one already in place I'm going to close this. Edit: If anything we might decide further down the line that the approach for overwrites might be better implemented as a pseudo manager, resulting in , |
Please describe the changes this PR makes and why it should be merged: There were methods for creating and updating permission overwrites in a channel, but not for deleting them, so I added one. It doesn't support a reason due to apparent Discord API limitations so the only parameter it supports is the User or Role resolvable
Status
Semantic versioning classification: