docs: align webhook method return types with implementation (#8253)

This commit is contained in:
Almeida
2022-07-17 20:14:25 +01:00
committed by GitHub
parent 452dec57ca
commit 5aeed99350
4 changed files with 56 additions and 8 deletions

View File

@@ -42,12 +42,32 @@ class WebhookClient extends BaseClient {
} }
// These are here only for documentation purposes - they are implemented by Webhook // These are here only for documentation purposes - they are implemented by Webhook
/* eslint-disable no-empty-function */ /* eslint-disable no-empty-function, valid-jsdoc */
/**
* Sends a message with this webhook.
* @param {string|MessagePayload|WebhookMessageOptions} options The content for the reply
* @returns {Promise<APIMessage>}
*/
send() {} send() {}
sendSlackMessage() {}
/**
* Gets a message that was sent by this webhook.
* @param {Snowflake} message The id of the message to fetch
* @param {WebhookFetchMessageOptions} [options={}] The options to provide to fetch the message.
* @returns {Promise<APIMessage>} Returns the message sent by this webhook
*/
fetchMessage() {} fetchMessage() {}
edit() {}
/**
* Edits a message that was sent by this webhook.
* @param {MessageResolvable} message The message to edit
* @param {string|MessagePayload|WebhookEditMessageOptions} options The options to provide
* @returns {Promise<APIMessage>} Returns the message edited by this webhook
*/
editMessage() {} editMessage() {}
sendSlackMessage() {}
edit() {}
delete() {} delete() {}
deleteMessage() {} deleteMessage() {}
get createdTimestamp() {} get createdTimestamp() {}

View File

@@ -148,7 +148,7 @@ class Webhook {
/** /**
* Sends a message with this webhook. * Sends a message with this webhook.
* @param {string|MessagePayload|WebhookMessageOptions} options The options to provide * @param {string|MessagePayload|WebhookMessageOptions} options The options to provide
* @returns {Promise<APIMessage>} * @returns {Promise<Message>}
* @example * @example
* // Send a basic message * // Send a basic message
* webhook.send('hello!') * webhook.send('hello!')
@@ -288,7 +288,7 @@ class Webhook {
* Gets a message that was sent by this webhook. * Gets a message that was sent by this webhook.
* @param {Snowflake|'@original'} message The id of the message to fetch * @param {Snowflake|'@original'} message The id of the message to fetch
* @param {WebhookFetchMessageOptions} [options={}] The options to provide to fetch the message. * @param {WebhookFetchMessageOptions} [options={}] The options to provide to fetch the message.
* @returns {Promise<APIMessage>} Returns the message sent by this webhook * @returns {Promise<Message>} Returns the message sent by this webhook
*/ */
async fetchMessage(message, { threadId } = {}) { async fetchMessage(message, { threadId } = {}) {
if (!this.token) throw new Error(ErrorCodes.WebhookTokenUnavailable); if (!this.token) throw new Error(ErrorCodes.WebhookTokenUnavailable);
@@ -309,7 +309,7 @@ class Webhook {
* Edits a message that was sent by this webhook. * Edits a message that was sent by this webhook.
* @param {MessageResolvable|'@original'} message The message to edit * @param {MessageResolvable|'@original'} message The message to edit
* @param {string|MessagePayload|WebhookEditMessageOptions} options The options to provide * @param {string|MessagePayload|WebhookEditMessageOptions} options The options to provide
* @returns {Promise<APIMessage>} Returns the message edited by this webhook * @returns {Promise<Message>} Returns the message edited by this webhook
*/ */
async editMessage(message, options) { async editMessage(message, options) {
if (!this.token) throw new Error(ErrorCodes.WebhookTokenUnavailable); if (!this.token) throw new Error(ErrorCodes.WebhookTokenUnavailable);

View File

@@ -1570,10 +1570,10 @@ export class InteractionWebhook extends PartialWebhookMixin() {
public token: string; public token: string;
public send(options: string | MessagePayload | InteractionReplyOptions): Promise<Message>; public send(options: string | MessagePayload | InteractionReplyOptions): Promise<Message>;
public editMessage( public editMessage(
message: MessageResolvable, message: MessageResolvable | '@original',
options: string | MessagePayload | WebhookEditMessageOptions, options: string | MessagePayload | WebhookEditMessageOptions,
): Promise<Message>; ): Promise<Message>;
public fetchMessage(message: string): Promise<Message>; public fetchMessage(message: Snowflake | '@original'): Promise<Message>;
} }
export class Invite extends Base { export class Invite extends Base {
@@ -2804,6 +2804,13 @@ export class Webhook extends WebhookMixin() {
applicationId: null; applicationId: null;
owner: User | APIUser; owner: User | APIUser;
}; };
public editMessage(
message: MessageResolvable,
options: string | MessagePayload | WebhookEditMessageOptions,
): Promise<Message>;
public fetchMessage(message: Snowflake, options?: WebhookFetchMessageOptions): Promise<Message>;
public send(options: string | MessagePayload | Omit<WebhookMessageOptions, 'flags'>): Promise<Message>;
} }
export class WebhookClient extends WebhookMixin(BaseClient) { export class WebhookClient extends WebhookMixin(BaseClient) {

View File

@@ -23,6 +23,7 @@ import {
APITextInputComponent, APITextInputComponent,
APIEmbed, APIEmbed,
ApplicationCommandType, ApplicationCommandType,
APIMessage,
} from 'discord-api-types/v10'; } from 'discord-api-types/v10';
import { import {
ApplicationCommand, ApplicationCommand,
@@ -130,6 +131,9 @@ import {
ThreadMemberManager, ThreadMemberManager,
CollectedMessageInteraction, CollectedMessageInteraction,
ShardEvents, ShardEvents,
Webhook,
WebhookClient,
InteractionWebhook,
} from '.'; } from '.';
import { expectAssignable, expectNotAssignable, expectNotType, expectType } from 'tsd'; import { expectAssignable, expectNotAssignable, expectNotType, expectType } from 'tsd';
import type { ContextMenuCommandBuilder, SlashCommandBuilder } from '@discordjs/builders'; import type { ContextMenuCommandBuilder, SlashCommandBuilder } from '@discordjs/builders';
@@ -1691,3 +1695,20 @@ expectType<ChannelMention>(partialGroupDMChannel.toString());
expectType<UserMention>(dmChannel.toString()); expectType<UserMention>(dmChannel.toString());
expectType<UserMention>(user.toString()); expectType<UserMention>(user.toString());
expectType<UserMention>(guildMember.toString()); expectType<UserMention>(guildMember.toString());
declare const webhook: Webhook;
declare const webhookClient: WebhookClient;
declare const interactionWebhook: InteractionWebhook;
declare const snowflake: Snowflake;
expectType<Promise<Message>>(webhook.send('content'));
expectType<Promise<Message>>(webhook.editMessage(snowflake, 'content'));
expectType<Promise<Message>>(webhook.fetchMessage(snowflake));
expectType<Promise<APIMessage>>(webhookClient.send('content'));
expectType<Promise<APIMessage>>(webhookClient.editMessage(snowflake, 'content'));
expectType<Promise<APIMessage>>(webhookClient.fetchMessage(snowflake));
expectType<Promise<Message>>(interactionWebhook.send('content'));
expectType<Promise<Message>>(interactionWebhook.editMessage(snowflake, 'content'));
expectType<Promise<Message>>(interactionWebhook.fetchMessage(snowflake));