mirror of
https://github.com/discordjs/discord.js.git
synced 2024-08-21 04:54:42 +12:00
types: generic for Webhook type (#10188)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
parent
654f1a48b9
commit
980a2b71c7
2 changed files with 31 additions and 37 deletions
64
packages/discord.js/typings/index.d.ts
vendored
64
packages/discord.js/typings/index.d.ts
vendored
|
@ -1434,7 +1434,7 @@ export class Guild extends AnonymousGuild {
|
||||||
public fetchPreview(): Promise<GuildPreview>;
|
public fetchPreview(): Promise<GuildPreview>;
|
||||||
public fetchTemplates(): Promise<Collection<GuildTemplate['code'], GuildTemplate>>;
|
public fetchTemplates(): Promise<Collection<GuildTemplate['code'], GuildTemplate>>;
|
||||||
public fetchVanityData(): Promise<Vanity>;
|
public fetchVanityData(): Promise<Vanity>;
|
||||||
public fetchWebhooks(): Promise<Collection<Snowflake, Webhook>>;
|
public fetchWebhooks(): Promise<Collection<Snowflake, Webhook<WebhookType.ChannelFollower | WebhookType.Incoming>>>;
|
||||||
public fetchWelcomeScreen(): Promise<WelcomeScreen>;
|
public fetchWelcomeScreen(): Promise<WelcomeScreen>;
|
||||||
public fetchWidget(): Promise<Widget>;
|
public fetchWidget(): Promise<Widget>;
|
||||||
public fetchWidgetSettings(): Promise<GuildWidgetSettings>;
|
public fetchWidgetSettings(): Promise<GuildWidgetSettings>;
|
||||||
|
@ -1476,7 +1476,7 @@ export class Guild extends AnonymousGuild {
|
||||||
export class GuildAuditLogs<Event extends GuildAuditLogsResolvable = AuditLogEvent> {
|
export class GuildAuditLogs<Event extends GuildAuditLogsResolvable = AuditLogEvent> {
|
||||||
private constructor(guild: Guild, data: RawGuildAuditLogData);
|
private constructor(guild: Guild, data: RawGuildAuditLogData);
|
||||||
private applicationCommands: Collection<Snowflake, ApplicationCommand>;
|
private applicationCommands: Collection<Snowflake, ApplicationCommand>;
|
||||||
private webhooks: Collection<Snowflake, Webhook>;
|
private webhooks: Collection<Snowflake, Webhook<WebhookType.ChannelFollower | WebhookType.Incoming>>;
|
||||||
private integrations: Collection<Snowflake | string, Integration>;
|
private integrations: Collection<Snowflake | string, Integration>;
|
||||||
private guildScheduledEvents: Collection<Snowflake, GuildScheduledEvent>;
|
private guildScheduledEvents: Collection<Snowflake, GuildScheduledEvent>;
|
||||||
private autoModerationRules: Collection<Snowflake, AutoModerationRule>;
|
private autoModerationRules: Collection<Snowflake, AutoModerationRule>;
|
||||||
|
@ -3529,8 +3529,8 @@ export class VoiceState extends Base {
|
||||||
}
|
}
|
||||||
|
|
||||||
// tslint:disable-next-line no-empty-interface
|
// tslint:disable-next-line no-empty-interface
|
||||||
export interface Webhook extends WebhookFields {}
|
export interface Webhook<Type extends WebhookType = WebhookType> extends WebhookFields {}
|
||||||
export class Webhook {
|
export class Webhook<Type extends WebhookType = WebhookType> {
|
||||||
private constructor(client: Client<true>, data?: RawWebhookData);
|
private constructor(client: Client<true>, data?: RawWebhookData);
|
||||||
public avatar: string | null;
|
public avatar: string | null;
|
||||||
public avatarURL(options?: ImageURLOptions): string | null;
|
public avatarURL(options?: ImageURLOptions): string | null;
|
||||||
|
@ -3538,35 +3538,23 @@ export class Webhook {
|
||||||
public readonly client: Client;
|
public readonly client: Client;
|
||||||
public guildId: Snowflake;
|
public guildId: Snowflake;
|
||||||
public name: string;
|
public name: string;
|
||||||
public owner: User | APIUser | null;
|
public owner: Type extends WebhookType.Incoming ? User | APIUser | null : User | APIUser;
|
||||||
public sourceGuild: Guild | APIPartialGuild | null;
|
public sourceGuild: Type extends WebhookType.ChannelFollower ? Guild | APIPartialGuild : null;
|
||||||
public sourceChannel: NewsChannel | APIPartialChannel | null;
|
public sourceChannel: Type extends WebhookType.ChannelFollower ? NewsChannel | APIPartialChannel : null;
|
||||||
public token: string | null;
|
public token: Type extends WebhookType.Incoming
|
||||||
public type: WebhookType;
|
? string
|
||||||
public applicationId: Snowflake | null;
|
: 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 get channel(): TextChannel | VoiceChannel | NewsChannel | StageChannel | ForumChannel | MediaChannel | null;
|
||||||
public isUserCreated(): this is this & {
|
public isUserCreated(): this is Webhook<WebhookType.Incoming> & {
|
||||||
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;
|
|
||||||
owner: User | APIUser;
|
owner: User | APIUser;
|
||||||
};
|
};
|
||||||
|
public isApplicationCreated(): this is Webhook<WebhookType.Application>;
|
||||||
|
public isIncoming(): this is Webhook<WebhookType.Incoming>;
|
||||||
|
public isChannelFollower(): this is Webhook<WebhookType.ChannelFollower>;
|
||||||
|
|
||||||
public editMessage(
|
public editMessage(
|
||||||
message: MessageResolvable,
|
message: MessageResolvable,
|
||||||
|
@ -4192,14 +4180,16 @@ export class GuildChannelManager extends CachedManager<Snowflake, GuildBasedChan
|
||||||
options: GuildChannelCreateOptions & { type: Type },
|
options: GuildChannelCreateOptions & { type: Type },
|
||||||
): Promise<MappedGuildChannelTypes[Type]>;
|
): Promise<MappedGuildChannelTypes[Type]>;
|
||||||
public create(options: GuildChannelCreateOptions): Promise<TextChannel>;
|
public create(options: GuildChannelCreateOptions): Promise<TextChannel>;
|
||||||
public createWebhook(options: WebhookCreateOptions): Promise<Webhook>;
|
public createWebhook(options: WebhookCreateOptions): Promise<Webhook<WebhookType.Incoming>>;
|
||||||
public edit(channel: GuildChannelResolvable, data: GuildChannelEditOptions): Promise<GuildChannel>;
|
public edit(channel: GuildChannelResolvable, data: GuildChannelEditOptions): Promise<GuildChannel>;
|
||||||
public fetch(id: Snowflake, options?: BaseFetchOptions): Promise<GuildBasedChannel | null>;
|
public fetch(id: Snowflake, options?: BaseFetchOptions): Promise<GuildBasedChannel | null>;
|
||||||
public fetch(
|
public fetch(
|
||||||
id?: undefined,
|
id?: undefined,
|
||||||
options?: BaseFetchOptions,
|
options?: BaseFetchOptions,
|
||||||
): Promise<Collection<Snowflake, NonThreadGuildBasedChannel | null>>;
|
): Promise<Collection<Snowflake, NonThreadGuildBasedChannel | null>>;
|
||||||
public fetchWebhooks(channel: GuildChannelResolvable): Promise<Collection<Snowflake, Webhook>>;
|
public fetchWebhooks(
|
||||||
|
channel: GuildChannelResolvable,
|
||||||
|
): Promise<Collection<Snowflake, Webhook<WebhookType.ChannelFollower | WebhookType.Incoming>>>;
|
||||||
public setPosition(
|
public setPosition(
|
||||||
channel: GuildChannelResolvable,
|
channel: GuildChannelResolvable,
|
||||||
position: number,
|
position: number,
|
||||||
|
@ -4553,8 +4543,8 @@ export interface TextBasedChannelFields<InGuild extends boolean = boolean>
|
||||||
options?: MessageChannelCollectorOptionsParams<ComponentType, true>,
|
options?: MessageChannelCollectorOptionsParams<ComponentType, true>,
|
||||||
): InteractionCollector<MappedInteractionTypes[ComponentType]>;
|
): InteractionCollector<MappedInteractionTypes[ComponentType]>;
|
||||||
createMessageCollector(options?: MessageCollectorOptions): MessageCollector;
|
createMessageCollector(options?: MessageCollectorOptions): MessageCollector;
|
||||||
createWebhook(options: ChannelWebhookCreateOptions): Promise<Webhook>;
|
createWebhook(options: ChannelWebhookCreateOptions): Promise<Webhook<WebhookType.Incoming>>;
|
||||||
fetchWebhooks(): Promise<Collection<Snowflake, Webhook>>;
|
fetchWebhooks(): Promise<Collection<Snowflake, Webhook<WebhookType.ChannelFollower | WebhookType.Incoming>>>;
|
||||||
sendTyping(): Promise<void>;
|
sendTyping(): Promise<void>;
|
||||||
setRateLimitPerUser(rateLimitPerUser: number, reason?: string): Promise<this>;
|
setRateLimitPerUser(rateLimitPerUser: number, reason?: string): Promise<this>;
|
||||||
setNSFW(nsfw?: boolean, reason?: string): Promise<this>;
|
setNSFW(nsfw?: boolean, reason?: string): Promise<this>;
|
||||||
|
@ -4580,7 +4570,7 @@ export interface WebhookFields extends PartialWebhookFields {
|
||||||
get createdAt(): Date;
|
get createdAt(): Date;
|
||||||
get createdTimestamp(): number;
|
get createdTimestamp(): number;
|
||||||
delete(reason?: string): Promise<void>;
|
delete(reason?: string): Promise<void>;
|
||||||
edit(options: WebhookEditOptions): Promise<Webhook>;
|
edit(options: WebhookEditOptions): Promise<this>;
|
||||||
sendSlackMessage(body: unknown): Promise<boolean>;
|
sendSlackMessage(body: unknown): Promise<boolean>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5736,7 +5726,7 @@ export interface GuildAuditLogsEntryExtraField {
|
||||||
export interface GuildAuditLogsEntryTargetField<TActionType extends GuildAuditLogsActionType> {
|
export interface GuildAuditLogsEntryTargetField<TActionType extends GuildAuditLogsActionType> {
|
||||||
User: User | null;
|
User: User | null;
|
||||||
Guild: Guild;
|
Guild: Guild;
|
||||||
Webhook: Webhook;
|
Webhook: Webhook<WebhookType.ChannelFollower | WebhookType.Incoming>;
|
||||||
Invite: Invite;
|
Invite: Invite;
|
||||||
Message: TActionType extends AuditLogEvent.MessageBulkDelete ? Guild | { id: Snowflake } : User;
|
Message: TActionType extends AuditLogEvent.MessageBulkDelete ? Guild | { id: Snowflake } : User;
|
||||||
Integration: Integration;
|
Integration: Integration;
|
||||||
|
@ -6337,7 +6327,7 @@ export type MessageTarget =
|
||||||
| TextBasedChannel
|
| TextBasedChannel
|
||||||
| User
|
| User
|
||||||
| GuildMember
|
| GuildMember
|
||||||
| Webhook
|
| Webhook<WebhookType.Incoming>
|
||||||
| WebhookClient
|
| WebhookClient
|
||||||
| Message
|
| Message
|
||||||
| MessageManager;
|
| MessageManager;
|
||||||
|
|
|
@ -32,6 +32,7 @@ import {
|
||||||
APIChannelSelectComponent,
|
APIChannelSelectComponent,
|
||||||
APIMentionableSelectComponent,
|
APIMentionableSelectComponent,
|
||||||
APIModalInteractionResponseCallbackData,
|
APIModalInteractionResponseCallbackData,
|
||||||
|
WebhookType,
|
||||||
} from 'discord-api-types/v10';
|
} from 'discord-api-types/v10';
|
||||||
import {
|
import {
|
||||||
ApplicationCommand,
|
ApplicationCommand,
|
||||||
|
@ -538,8 +539,10 @@ client.on('messageCreate', async message => {
|
||||||
if (webhook.isChannelFollower()) {
|
if (webhook.isChannelFollower()) {
|
||||||
expectAssignable<Guild | APIPartialGuild>(webhook.sourceGuild);
|
expectAssignable<Guild | APIPartialGuild>(webhook.sourceGuild);
|
||||||
expectAssignable<NewsChannel | APIPartialChannel>(webhook.sourceChannel);
|
expectAssignable<NewsChannel | APIPartialChannel>(webhook.sourceChannel);
|
||||||
|
expectType<Webhook<WebhookType.ChannelFollower>>(webhook);
|
||||||
} else if (webhook.isIncoming()) {
|
} else if (webhook.isIncoming()) {
|
||||||
expectType<string>(webhook.token);
|
expectType<string>(webhook.token);
|
||||||
|
expectType<Webhook<WebhookType.Incoming>>(webhook);
|
||||||
}
|
}
|
||||||
|
|
||||||
expectNotType<Guild | APIPartialGuild>(webhook.sourceGuild);
|
expectNotType<Guild | APIPartialGuild>(webhook.sourceGuild);
|
||||||
|
@ -2344,6 +2347,7 @@ declare const snowflake: Snowflake;
|
||||||
expectType<Promise<Message>>(webhook.send('content'));
|
expectType<Promise<Message>>(webhook.send('content'));
|
||||||
expectType<Promise<Message>>(webhook.editMessage(snowflake, 'content'));
|
expectType<Promise<Message>>(webhook.editMessage(snowflake, 'content'));
|
||||||
expectType<Promise<Message>>(webhook.fetchMessage(snowflake));
|
expectType<Promise<Message>>(webhook.fetchMessage(snowflake));
|
||||||
|
expectType<Promise<Webhook>>(webhook.edit({ name: 'name' }));
|
||||||
|
|
||||||
expectType<Promise<APIMessage>>(webhookClient.send('content'));
|
expectType<Promise<APIMessage>>(webhookClient.send('content'));
|
||||||
expectType<Promise<APIMessage>>(webhookClient.editMessage(snowflake, 'content'));
|
expectType<Promise<APIMessage>>(webhookClient.editMessage(snowflake, 'content'));
|
||||||
|
|
Loading…
Reference in a new issue