Skip to content

typings(webhooks): Incoming webhook #9182

Closed
@DraftProducts

Description

@DraftProducts

Which package is this bug report for?

discord.js

Issue description

Actually, we have 3 types of webhooks :

  • Incoming: Incoming Webhooks can post messages to channels with a generated token
  • ChannelFollower: Channel Follower Webhooks are internal webhooks used with Channel Following to post new messages into channels
  • Application: Application webhooks are webhooks used with Interactions

The method <TextBasedChannel>.createWebhook() returns an Incoming Webhook, but an .isIncoming() call is needed to apply correct typings.
The Webhook typing structure should have an Incoming default flag (like Cached flag in interactions) and could be changed internally for Interactions usage (or something similar like Types extend in a union).

I can assume the fix if this suggestion is accepted ✌️

Code sample

Here an example of what could be done.

export type WebhookTypeReducer<
  State extends WebhookType,
  Target extends WebhookType,
  Type,
  Fallback = null,
> = State extends Target
  ? Type
  : State extends Exclude<WebhookType, Target>
  ? null
  : Type | null;

export class Webhook<Type extends WebhookType = WebhookType> extends WebhookMixin() {
  // [...]
  public sourceGuild: WebhookTypeReducer<Type, WebhookType.ChannelFollower, Guild | APIPartialGuild>;
  public sourceChannel: WebhookTypeReducer<Type, WebhookType.ChannelFollower, NewsChannel | APIPartialChannel>;
  public token: WebhookTypeReducer<Type, WebhookType.Incoming, string>;
  public applicationId: WebhookTypeReducer<Type, WebhookType.Application, Snowflake>;
}
export interface TextBasedChannelFields {
  // [...]
  createWebhook(options: ChannelWebhookCreateOptions): Promise<Webhook<WebhookType.Incoming>>;
  fetchWebhooks(): Promise<Collection<Snowflake, Webhook>>;
}

Package version

main

Priority this issue should have

Low (slightly annoying)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions