From 225778823e8c2433fa30097793f82cc883716421 Mon Sep 17 00:00:00 2001 From: JustEvil <71156616+EvilG-MC@users.noreply.github.com> Date: Sun, 2 Mar 2025 21:08:41 -0600 Subject: [PATCH] feat: return channel type in channel guild create (#334) * feat: return channel type in channel guild create also, my skill issue forced me to create a new type * refactor: use SeyfertChannelMap --- src/common/shorters/guilds.ts | 17 ++++++++++++++--- src/structures/channels.ts | 20 +++++++++++++++++--- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/common/shorters/guilds.ts b/src/common/shorters/guilds.ts index 1f2811b..4a32425 100644 --- a/src/common/shorters/guilds.ts +++ b/src/common/shorters/guilds.ts @@ -9,7 +9,15 @@ import { type StickerStructure, Transformers, } from '../../client/transformers'; -import { type AllChannels, BaseChannel, type CreateStickerBodyRequest, Guild, channelFrom } from '../../structures'; +import type { SeyfertChannelMap } from '../../commands'; +import { + type AllChannels, + BaseChannel, + type CreateStickerBodyRequest, + Guild, + type GuildChannelTypes, + channelFrom, +} from '../../structures'; import type { APIChannel, APISticker, @@ -153,10 +161,13 @@ export class GuildShorter extends BaseShorter { * @param body The data for creating the channel. * @returns A Promise that resolves to the created channel. */ - create: async (guildId: string, body: RESTPostAPIGuildChannelJSONBody) => { + create: async ( + guildId: string, + body: RESTPostAPIGuildChannelJSONBody & { type: T }, + ): Promise => { const res = await this.client.proxy.guilds(guildId).channels.post({ body }); await this.client.cache.channels?.setIfNI(CacheFrom.Rest, BaseChannel.__intent__(guildId), res.id, guildId, res); - return channelFrom(res, this.client); + return channelFrom(res, this.client) as SeyfertChannelMap[T]; }, /** diff --git a/src/structures/channels.ts b/src/structures/channels.ts index 7830b7d..12d9b13 100644 --- a/src/structures/channels.ts +++ b/src/structures/channels.ts @@ -22,7 +22,7 @@ import { type VoiceStateStructure, type WebhookStructure, } from '../client'; -import type { UsingClient } from '../commands'; +import type { SeyfertChannelMap, UsingClient } from '../commands'; import { type EmojiResolvable, type MessageCreateBodyRequest, @@ -167,8 +167,10 @@ export class BaseNoEditableChannel extends DiscordBase => ctx.client.guilds.channels.list(ctx.guildId, force), fetch: (id: string, force = false): Promise => ctx.client.guilds.channels.fetch(ctx.guildId, id, force), - create: (body: RESTPostAPIGuildChannelJSONBody): Promise => - ctx.client.guilds.channels.create(ctx.guildId, body), + create: ( + body: RESTPostAPIGuildChannelJSONBody & { type: T }, + ): Promise => + ctx.client.guilds.channels.create(ctx.guildId, body as never) as Promise, delete: (id: string, reason?: string): Promise => ctx.client.guilds.channels.delete(ctx.guildId, id, reason), edit: (id: string, body: RESTPatchAPIChannelJSONBody, reason?: string): Promise => @@ -689,3 +691,15 @@ export type AllChannels = | NewsChannelStructure | DirectoryChannelStructure | StageChannelStructure; + +export type GuildChannelTypes = + | ChannelType.GuildAnnouncement + | ChannelType.GuildVoice + | ChannelType.GuildText + | ChannelType.GuildStageVoice + | ChannelType.GuildForum + | ChannelType.GuildMedia + | ChannelType.GuildCategory + | ChannelType.AnnouncementThread + | ChannelType.PrivateThread + | ChannelType.PublicThread;