From 78381a56cf9a122d0a44ab1b0966cb0d7691ad7d Mon Sep 17 00:00:00 2001 From: David Malchin Date: Thu, 6 Jul 2023 16:55:29 +0300 Subject: [PATCH] feat(ChannelsAPI): add permission overwrites (#9651) Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- packages/core/src/api/channel.ts | 42 ++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/packages/core/src/api/channel.ts b/packages/core/src/api/channel.ts index b4f66756aa21..8fcf035dd93e 100644 --- a/packages/core/src/api/channel.ts +++ b/packages/core/src/api/channel.ts @@ -27,6 +27,7 @@ import { type RESTPostAPIChannelMessageCrosspostResult, type RESTPostAPIChannelMessageJSONBody, type RESTPostAPIChannelMessageResult, + type RESTPutAPIChannelPermissionJSONBody, type Snowflake, type RESTPostAPIChannelThreadsJSONBody, type RESTPostAPIChannelThreadsResult, @@ -540,4 +541,45 @@ export class ChannelsAPI { public async getWebhooks(channelId: Snowflake) { return this.rest.get(Routes.channelWebhooks(channelId)) as Promise; } + + /** + * Edits the permission overwrite for a user or role in a channel + * + * @see {@link https://discord.com/developers/docs/resources/channel#edit-channel-permissions} + * @param channelId - The id of the channel to edit the permission overwrite in + * @param overwriteId - The id of the user or role to edit the permission overwrite for + * @param body - The data for editing the permission overwrite + * @param options - The options for editing the permission overwrite + */ + public async editPermissionOverwrite( + channelId: Snowflake, + overwriteId: Snowflake, + body: RESTPutAPIChannelPermissionJSONBody, + { reason, signal }: Pick = {}, + ) { + await this.rest.put(Routes.channelPermission(channelId, overwriteId), { + reason, + body, + signal, + }); + } + + /** + * Deletes the permission overwrite for a user or role in a channel + * + * @see {@link https://discord.com/developers/docs/resources/channel#delete-channel-permission} + * @param channelId - The id of the channel to delete the permission overwrite in + * @param overwriteId - The id of the user or role to delete the permission overwrite for + * @param options - The options for deleting the permission overwrite + */ + public async deletePermissionOverwrite( + channelId: Snowflake, + overwriteId: Snowflake, + { reason, signal }: Pick = {}, + ) { + await this.rest.delete(Routes.channelPermission(channelId, overwriteId), { + reason, + signal, + }); + } }