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.**