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
This commit is contained in:
JustEvil 2025-03-02 21:08:41 -06:00 committed by GitHub
parent 84a0ce6754
commit 225778823e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 6 deletions

View File

@ -9,7 +9,15 @@ import {
type StickerStructure, type StickerStructure,
Transformers, Transformers,
} from '../../client/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 { import type {
APIChannel, APIChannel,
APISticker, APISticker,
@ -153,10 +161,13 @@ export class GuildShorter extends BaseShorter {
* @param body The data for creating the channel. * @param body The data for creating the channel.
* @returns A Promise that resolves to the created channel. * @returns A Promise that resolves to the created channel.
*/ */
create: async (guildId: string, body: RESTPostAPIGuildChannelJSONBody) => { create: async <T extends GuildChannelTypes = GuildChannelTypes>(
guildId: string,
body: RESTPostAPIGuildChannelJSONBody & { type: T },
): Promise<SeyfertChannelMap[T]> => {
const res = await this.client.proxy.guilds(guildId).channels.post({ body }); 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); 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];
}, },
/** /**

View File

@ -22,7 +22,7 @@ import {
type VoiceStateStructure, type VoiceStateStructure,
type WebhookStructure, type WebhookStructure,
} from '../client'; } from '../client';
import type { UsingClient } from '../commands'; import type { SeyfertChannelMap, UsingClient } from '../commands';
import { import {
type EmojiResolvable, type EmojiResolvable,
type MessageCreateBodyRequest, type MessageCreateBodyRequest,
@ -167,8 +167,10 @@ export class BaseNoEditableChannel<T extends ChannelType> extends DiscordBase<AP
list: (force = false): Promise<AllChannels[]> => ctx.client.guilds.channels.list(ctx.guildId, force), list: (force = false): Promise<AllChannels[]> => ctx.client.guilds.channels.list(ctx.guildId, force),
fetch: (id: string, force = false): Promise<AllChannels> => fetch: (id: string, force = false): Promise<AllChannels> =>
ctx.client.guilds.channels.fetch(ctx.guildId, id, force), ctx.client.guilds.channels.fetch(ctx.guildId, id, force),
create: (body: RESTPostAPIGuildChannelJSONBody): Promise<AllChannels> => create: <T extends GuildChannelTypes = GuildChannelTypes>(
ctx.client.guilds.channels.create(ctx.guildId, body), body: RESTPostAPIGuildChannelJSONBody & { type: T },
): Promise<SeyfertChannelMap[T]> =>
ctx.client.guilds.channels.create(ctx.guildId, body as never) as Promise<SeyfertChannelMap[T]>,
delete: (id: string, reason?: string): Promise<AllChannels> => delete: (id: string, reason?: string): Promise<AllChannels> =>
ctx.client.guilds.channels.delete(ctx.guildId, id, reason), ctx.client.guilds.channels.delete(ctx.guildId, id, reason),
edit: (id: string, body: RESTPatchAPIChannelJSONBody, reason?: string): Promise<AllChannels> => edit: (id: string, body: RESTPatchAPIChannelJSONBody, reason?: string): Promise<AllChannels> =>
@ -689,3 +691,15 @@ export type AllChannels =
| NewsChannelStructure | NewsChannelStructure
| DirectoryChannelStructure | DirectoryChannelStructure
| StageChannelStructure; | StageChannelStructure;
export type GuildChannelTypes =
| ChannelType.GuildAnnouncement
| ChannelType.GuildVoice
| ChannelType.GuildText
| ChannelType.GuildStageVoice
| ChannelType.GuildForum
| ChannelType.GuildMedia
| ChannelType.GuildCategory
| ChannelType.AnnouncementThread
| ChannelType.PrivateThread
| ChannelType.PublicThread;