feat(Interactions): add InteractionWebhook for better internals (#5712)

This commit is contained in:
ckohen
2021-06-05 16:41:23 -07:00
committed by GitHub
parent 1d57754d46
commit dec191aa1e
9 changed files with 120 additions and 36 deletions

45
typings/index.d.ts vendored
View File

@@ -467,7 +467,7 @@ declare module 'discord.js' {
public deferred: boolean;
public options: Collection<string, CommandInteractionOption>;
public replied: boolean;
public webhook: WebhookClient;
public webhook: InteractionWebhook;
public defer(options?: InteractionDeferOptions): Promise<void>;
public deleteReply(): Promise<void>;
public editReply(
@@ -1139,6 +1139,30 @@ declare module 'discord.js' {
public isMessageComponent(): this is MessageComponentInteraction;
}
export class InteractionWebhook extends PartialWebhookMixin() {
constructor(client: Client, id: Snowflake, token: string);
public token: string;
public send(
content: string | (InteractionReplyOptions & { split?: false }) | MessageAdditions,
): Promise<Message | RawMessage>;
public send(options: InteractionReplyOptions & { split: true | SplitOptions }): Promise<(Message | RawMessage)[]>;
public send(
options: InteractionReplyOptions | APIMessage,
): Promise<Message | RawMessage | (Message | RawMessage)[]>;
public send(
content: string | null,
options: (InteractionReplyOptions & { split?: false }) | MessageAdditions,
): Promise<Message | RawMessage>;
public send(
content: string | null,
options: InteractionReplyOptions & { split: true | SplitOptions },
): Promise<(Message | RawMessage)[]>;
public send(
content: string | null,
options: InteractionReplyOptions,
): Promise<Message | RawMessage | (Message | RawMessage)[]>;
}
export class Invite extends Base {
constructor(client: Client, data: unknown);
public channel: GuildChannel | PartialGroupDMChannel;
@@ -1333,7 +1357,7 @@ declare module 'discord.js' {
public deferred: boolean;
public message: Message | RawMessage;
public replied: boolean;
public webhook: WebhookClient;
public webhook: InteractionWebhook;
public defer(options?: InteractionDeferOptions): Promise<void>;
public deferUpdate(): Promise<void>;
public deleteReply(): Promise<void>;
@@ -2498,18 +2522,15 @@ declare module 'discord.js' {
stopTyping(force?: boolean): void;
}
function PartialWebhookMixin<T>(Base?: Constructable<T>): Constructable<T & PartialWebhookFields>;
function WebhookMixin<T>(Base?: Constructable<T>): Constructable<T & WebhookFields>;
function VolumeMixin<T>(base: Constructable<T>): Constructable<T & VolumeInterface>;
interface WebhookFields {
interface PartialWebhookFields {
id: Snowflake;
readonly createdAt: Date;
readonly createdTimestamp: number;
readonly url: string;
delete(reason?: string): Promise<void>;
deleteMessage(message: MessageResolvable | '@original'): Promise<void>;
edit(options: WebhookEditData): Promise<Webhook>;
editMessage(
message: MessageResolvable | '@original',
content: string | null | APIMessage | MessageAdditions,
@@ -2537,7 +2558,14 @@ declare module 'discord.js' {
content: string | null,
options: WebhookMessageOptions,
): Promise<Message | RawMessage | (Message | RawMessage)[]>;
sendSlackMessage(body: unknown): Promise<boolean>;
}
interface WebhookFields extends PartialWebhookFields {
readonly createdAt: Date;
readonly createdTimestamp: number;
delete(reason?: string): Promise<void>;
edit(options: WebhookEditData): Promise<Webhook>;
sendSlackMessage(body: object): Promise<boolean>;
}
//#endregion
@@ -3532,6 +3560,7 @@ declare module 'discord.js' {
type MessageTarget =
| Interaction
| InteractionWebhook
| TextChannel
| NewsChannel
| DMChannel