From 2cc513b874bd49aef51513af4489bcc9edc6aaed Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Wed, 20 Jan 2021 10:43:35 +0100 Subject: [PATCH] feat(handlers): add editChannelOverwrite() & deleteChannelOverwrite() (#403) * add editChannelOverwrite function * remove body constant Co-authored-by: Ayyan * format * Update src/api/handlers/guild.ts Co-authored-by: Ayyan * Update src/api/handlers/guild.ts Co-authored-by: Ayyan * add deleteChannelOverwrite function * Mark permission in jsdoc Co-authored-by: Ayyan Co-authored-by: Ayyan --- src/api/handlers/guild.ts | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/api/handlers/guild.ts b/src/api/handlers/guild.ts index 25e6cd7e8..6d6458a19 100644 --- a/src/api/handlers/guild.ts +++ b/src/api/handlers/guild.ts @@ -25,6 +25,7 @@ import { ImageSize, Intents, MemberCreatePayload, + Overwrite, PositionSwap, PruneOptions, PrunePayload, @@ -206,6 +207,50 @@ export function swapChannels( ); } +/** Edit the channel permission overwrites for a user or role in this channel. Requires `MANAGE_ROLES` permission. */ +export async function editChannelOverwrite( + guildID: string, + channelID: string, + overwriteID: string, + options: Omit, +) { + const hasPerm = await botHasPermission( + guildID, + ["MANAGE_ROLES"], + ); + if (!hasPerm) { + throw new Error(Errors.MISSING_MANAGE_ROLES); + } + + return RequestManager.put( + endpoints.CHANNEL_OVERWRITE(channelID, overwriteID), + { + allow: calculateBits(options.allow), + deny: calculateBits(options.deny), + type: options.type, + }, + ); +} + +/** Delete the channel permission overwrites for a user or role in this channel. Requires `MANAGE_ROLES` permission. */ +export async function deleteChannelOverwrite( + guildID: string, + channelID: string, + overwriteID: string, +) { + const hasPerm = await botHasPermission( + guildID, + ["MANAGE_ROLES"], + ); + if (!hasPerm) { + throw new Error(Errors.MISSING_MANAGE_ROLES); + } + + return RequestManager.delete( + endpoints.CHANNEL_OVERWRITE(channelID, overwriteID), + ); +} + /** Returns a guild member object for the specified user. * * ⚠️ **ADVANCED USE ONLY: Your members will be cached in your guild most likely. Only use this when you are absolutely sure the member is not cached.**