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 <ayyantee@gmail.com>
This commit is contained in:
ITOH
2021-03-08 15:23:04 +01:00
committed by GitHub
parent 9715ab4274
commit ebc48156aa
2 changed files with 13 additions and 17 deletions
+12 -13
View File
@@ -112,30 +112,29 @@ export function guildBannerURL(
/** Create a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */ /** Create a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */
export async function createGuildChannel( export async function createGuildChannel(
guild: Guild, guildID: string,
name: string, name: string,
options?: ChannelCreateOptions, options?: ChannelCreateOptions,
) { ) {
const hasPerm = await botHasPermission( const hasPerm = await botHasPermission(
guild.id, guildID,
["MANAGE_CHANNELS"], ["MANAGE_CHANNELS"],
); );
if (!hasPerm) { if (!hasPerm) {
throw new Error(Errors.MISSING_MANAGE_CHANNELS); throw new Error(Errors.MISSING_MANAGE_CHANNELS);
} }
const result = const result = (await RequestManager.post(endpoints.GUILD_CHANNELS(guildID), {
(await RequestManager.post(endpoints.GUILD_CHANNELS(guild.id), { ...options,
...options, name,
name, permission_overwrites: options?.permissionOverwrites?.map((perm) => ({
permission_overwrites: options?.permissionOverwrites?.map((perm) => ({ ...perm,
...perm,
allow: calculateBits(perm.allow), allow: calculateBits(perm.allow),
deny: calculateBits(perm.deny), deny: calculateBits(perm.deny),
})), })),
type: options?.type || ChannelTypes.GUILD_TEXT, type: options?.type || ChannelTypes.GUILD_TEXT,
})) as ChannelCreatePayload; })) as ChannelCreatePayload;
const channelStruct = await structures.createChannel(result); const channelStruct = await structures.createChannel(result);
+1 -4
View File
@@ -138,10 +138,7 @@ Deno.test({
Deno.test({ Deno.test({
name: "[channel] create a channel in a guild", name: "[channel] create a channel in a guild",
async fn() { async fn() {
const guild = cache.guilds.get(tempData.guildID); const channel = await createGuildChannel(tempData.guildID, "test");
if (!guild) throw new Error("Guild not found");
const channel = await createGuildChannel(guild, "test");
// Assertions // Assertions
assertExists(channel); assertExists(channel);