Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typings(webhooks): Incoming webhook #9182

Closed
DraftProducts opened this issue Feb 28, 2023 · 0 comments · Fixed by #10188
Closed

typings(webhooks): Incoming webhook #9182

DraftProducts opened this issue Feb 28, 2023 · 0 comments · Fixed by #10188

Comments

@DraftProducts
Copy link
Contributor

DraftProducts commented Feb 28, 2023

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants