diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 57ff9e2c5..6d1051691 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -1434,7 +1434,7 @@ export class Guild extends AnonymousGuild { public fetchPreview(): Promise; public fetchTemplates(): Promise>; public fetchVanityData(): Promise; - public fetchWebhooks(): Promise>; + public fetchWebhooks(): Promise>>; public fetchWelcomeScreen(): Promise; public fetchWidget(): Promise; public fetchWidgetSettings(): Promise; @@ -1476,7 +1476,7 @@ export class Guild extends AnonymousGuild { export class GuildAuditLogs { private constructor(guild: Guild, data: RawGuildAuditLogData); private applicationCommands: Collection; - private webhooks: Collection; + private webhooks: Collection>; private integrations: Collection; private guildScheduledEvents: Collection; private autoModerationRules: Collection; @@ -3529,8 +3529,8 @@ export class VoiceState extends Base { } // tslint:disable-next-line no-empty-interface -export interface Webhook extends WebhookFields {} -export class Webhook { +export interface Webhook extends WebhookFields {} +export class Webhook { private constructor(client: Client, data?: RawWebhookData); public avatar: string | null; public avatarURL(options?: ImageURLOptions): string | null; @@ -3538,35 +3538,23 @@ export class Webhook { public readonly client: Client; public guildId: Snowflake; public name: string; - public owner: User | APIUser | null; - public sourceGuild: Guild | APIPartialGuild | null; - public sourceChannel: NewsChannel | APIPartialChannel | null; - public token: string | null; - public type: WebhookType; - public applicationId: Snowflake | null; + public owner: Type extends WebhookType.Incoming ? User | APIUser | null : User | APIUser; + public sourceGuild: Type extends WebhookType.ChannelFollower ? Guild | APIPartialGuild : null; + public sourceChannel: Type extends WebhookType.ChannelFollower ? NewsChannel | APIPartialChannel : null; + public token: Type extends WebhookType.Incoming + ? string + : Type extends WebhookType.ChannelFollower + ? null + : string | null; + public type: Type; + public applicationId: Type extends WebhookType.Application ? Snowflake : null; public get channel(): TextChannel | VoiceChannel | NewsChannel | StageChannel | ForumChannel | MediaChannel | null; - public isUserCreated(): this is this & { - type: WebhookType.Incoming; - applicationId: null; - owner: User | APIUser; - }; - public isApplicationCreated(): this is this & { - type: WebhookType.Application; - applicationId: Snowflake; - owner: User | APIUser; - }; - public isIncoming(): this is this & { - type: WebhookType.Incoming; - token: string; - }; - public isChannelFollower(): this is this & { - type: WebhookType.ChannelFollower; - sourceGuild: Guild | APIPartialGuild; - sourceChannel: NewsChannel | APIPartialChannel; - token: null; - applicationId: null; + public isUserCreated(): this is Webhook & { owner: User | APIUser; }; + public isApplicationCreated(): this is Webhook; + public isIncoming(): this is Webhook; + public isChannelFollower(): this is Webhook; public editMessage( message: MessageResolvable, @@ -4192,14 +4180,16 @@ export class GuildChannelManager extends CachedManager; public create(options: GuildChannelCreateOptions): Promise; - public createWebhook(options: WebhookCreateOptions): Promise; + public createWebhook(options: WebhookCreateOptions): Promise>; public edit(channel: GuildChannelResolvable, data: GuildChannelEditOptions): Promise; public fetch(id: Snowflake, options?: BaseFetchOptions): Promise; public fetch( id?: undefined, options?: BaseFetchOptions, ): Promise>; - public fetchWebhooks(channel: GuildChannelResolvable): Promise>; + public fetchWebhooks( + channel: GuildChannelResolvable, + ): Promise>>; public setPosition( channel: GuildChannelResolvable, position: number, @@ -4553,8 +4543,8 @@ export interface TextBasedChannelFields options?: MessageChannelCollectorOptionsParams, ): InteractionCollector; createMessageCollector(options?: MessageCollectorOptions): MessageCollector; - createWebhook(options: ChannelWebhookCreateOptions): Promise; - fetchWebhooks(): Promise>; + createWebhook(options: ChannelWebhookCreateOptions): Promise>; + fetchWebhooks(): Promise>>; sendTyping(): Promise; setRateLimitPerUser(rateLimitPerUser: number, reason?: string): Promise; setNSFW(nsfw?: boolean, reason?: string): Promise; @@ -4580,7 +4570,7 @@ export interface WebhookFields extends PartialWebhookFields { get createdAt(): Date; get createdTimestamp(): number; delete(reason?: string): Promise; - edit(options: WebhookEditOptions): Promise; + edit(options: WebhookEditOptions): Promise; sendSlackMessage(body: unknown): Promise; } @@ -5736,7 +5726,7 @@ export interface GuildAuditLogsEntryExtraField { export interface GuildAuditLogsEntryTargetField { User: User | null; Guild: Guild; - Webhook: Webhook; + Webhook: Webhook; Invite: Invite; Message: TActionType extends AuditLogEvent.MessageBulkDelete ? Guild | { id: Snowflake } : User; Integration: Integration; @@ -6337,7 +6327,7 @@ export type MessageTarget = | TextBasedChannel | User | GuildMember - | Webhook + | Webhook | WebhookClient | Message | MessageManager; diff --git a/packages/discord.js/typings/index.test-d.ts b/packages/discord.js/typings/index.test-d.ts index 980d95628..e3616c9f8 100644 --- a/packages/discord.js/typings/index.test-d.ts +++ b/packages/discord.js/typings/index.test-d.ts @@ -32,6 +32,7 @@ import { APIChannelSelectComponent, APIMentionableSelectComponent, APIModalInteractionResponseCallbackData, + WebhookType, } from 'discord-api-types/v10'; import { ApplicationCommand, @@ -538,8 +539,10 @@ client.on('messageCreate', async message => { if (webhook.isChannelFollower()) { expectAssignable(webhook.sourceGuild); expectAssignable(webhook.sourceChannel); + expectType>(webhook); } else if (webhook.isIncoming()) { expectType(webhook.token); + expectType>(webhook); } expectNotType(webhook.sourceGuild); @@ -2344,6 +2347,7 @@ declare const snowflake: Snowflake; expectType>(webhook.send('content')); expectType>(webhook.editMessage(snowflake, 'content')); expectType>(webhook.fetchMessage(snowflake)); +expectType>(webhook.edit({ name: 'name' })); expectType>(webhookClient.send('content')); expectType>(webhookClient.editMessage(snowflake, 'content'));