From ebc48156aa3c85fd3f7f9fb3debb836a69156a14 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Mon, 8 Mar 2021 15:23:04 +0100 Subject: [PATCH] feat(handlers/guild): change createGuildChannel() to use guild ID (#528) * guild > guildID * fix(test): createGuildChannel test * Update test/mod.test.ts * Update test/mod.test.ts * fmt Co-authored-by: ayntee --- src/api/handlers/guild.ts | 25 ++++++++++++------------- test/mod.test.ts | 5 +---- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/api/handlers/guild.ts b/src/api/handlers/guild.ts index 7a9023a9c..df04dc6b3 100644 --- a/src/api/handlers/guild.ts +++ b/src/api/handlers/guild.ts @@ -112,30 +112,29 @@ export function guildBannerURL( /** Create a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */ export async function createGuildChannel( - guild: Guild, + guildID: string, name: string, options?: ChannelCreateOptions, ) { const hasPerm = await botHasPermission( - guild.id, + guildID, ["MANAGE_CHANNELS"], ); if (!hasPerm) { throw new Error(Errors.MISSING_MANAGE_CHANNELS); } - const result = - (await RequestManager.post(endpoints.GUILD_CHANNELS(guild.id), { - ...options, - name, - permission_overwrites: options?.permissionOverwrites?.map((perm) => ({ - ...perm, + const result = (await RequestManager.post(endpoints.GUILD_CHANNELS(guildID), { + ...options, + name, + permission_overwrites: options?.permissionOverwrites?.map((perm) => ({ + ...perm, - allow: calculateBits(perm.allow), - deny: calculateBits(perm.deny), - })), - type: options?.type || ChannelTypes.GUILD_TEXT, - })) as ChannelCreatePayload; + allow: calculateBits(perm.allow), + deny: calculateBits(perm.deny), + })), + type: options?.type || ChannelTypes.GUILD_TEXT, + })) as ChannelCreatePayload; const channelStruct = await structures.createChannel(result); diff --git a/test/mod.test.ts b/test/mod.test.ts index 4cc7aab0b..a5632ea36 100644 --- a/test/mod.test.ts +++ b/test/mod.test.ts @@ -138,10 +138,7 @@ Deno.test({ Deno.test({ name: "[channel] create a channel in a guild", async fn() { - const guild = cache.guilds.get(tempData.guildID); - if (!guild) throw new Error("Guild not found"); - - const channel = await createGuildChannel(guild, "test"); + const channel = await createGuildChannel(tempData.guildID, "test"); // Assertions assertExists(channel);