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

feat: add typeguards to webhooks #6850

Merged
merged 5 commits into from Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/structures/Webhook.js
Expand Up @@ -395,6 +395,22 @@ class Webhook {
return this.client.rest.cdn.Avatar(this.id, this.avatar, format, size);
}

/**
* Whether or not this webhook is a channel follower webhook.
* @returns {boolean}
*/
isChannelFollower() {
return this.type === WebhookTypes['Channel Follower'];
}

/**
* Whether or not this webhook is an incoming webhook.
* @returns {boolean}
*/
isIncoming() {
return this.type === WebhookTypes.Incoming;
}

static applyToClass(structure, ignore = []) {
for (const prop of [
'send',
Expand Down
5 changes: 5 additions & 0 deletions typings/index.d.ts
Expand Up @@ -2204,6 +2204,11 @@ export class Webhook extends WebhookMixin() {
public sourceChannel: NewsChannel | APIPartialChannel | null;
public token: string | null;
public type: WebhookType;
public isIncoming(): this is this & { token: string };
public isChannelFollower(): this is this & {
sourceGuild: Guild | APIPartialGuild;
sourceChannel: NewsChannel | APIPartialChannel;
suneettipirneni marked this conversation as resolved.
Show resolved Hide resolved
};
}

export class WebhookClient extends WebhookMixin(BaseClient) {
Expand Down