mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
docs: align webhook method return types with implementation (#8253)
This commit is contained in:
@@ -42,12 +42,32 @@ class WebhookClient extends BaseClient {
|
||||
}
|
||||
|
||||
// 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() {}
|
||||
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() {}
|
||||
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() {}
|
||||
|
||||
sendSlackMessage() {}
|
||||
edit() {}
|
||||
delete() {}
|
||||
deleteMessage() {}
|
||||
get createdTimestamp() {}
|
||||
|
||||
@@ -148,7 +148,7 @@ class Webhook {
|
||||
/**
|
||||
* Sends a message with this webhook.
|
||||
* @param {string|MessagePayload|WebhookMessageOptions} options The options to provide
|
||||
* @returns {Promise<APIMessage>}
|
||||
* @returns {Promise<Message>}
|
||||
* @example
|
||||
* // Send a basic message
|
||||
* webhook.send('hello!')
|
||||
@@ -288,7 +288,7 @@ class Webhook {
|
||||
* Gets a message that was sent by this webhook.
|
||||
* @param {Snowflake|'@original'} 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
|
||||
* @returns {Promise<Message>} Returns the message sent by this webhook
|
||||
*/
|
||||
async fetchMessage(message, { threadId } = {}) {
|
||||
if (!this.token) throw new Error(ErrorCodes.WebhookTokenUnavailable);
|
||||
@@ -309,7 +309,7 @@ class Webhook {
|
||||
* Edits a message that was sent by this webhook.
|
||||
* @param {MessageResolvable|'@original'} message The message to edit
|
||||
* @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) {
|
||||
if (!this.token) throw new Error(ErrorCodes.WebhookTokenUnavailable);
|
||||
|
||||
11
packages/discord.js/typings/index.d.ts
vendored
11
packages/discord.js/typings/index.d.ts
vendored
@@ -1570,10 +1570,10 @@ export class InteractionWebhook extends PartialWebhookMixin() {
|
||||
public token: string;
|
||||
public send(options: string | MessagePayload | InteractionReplyOptions): Promise<Message>;
|
||||
public editMessage(
|
||||
message: MessageResolvable,
|
||||
message: MessageResolvable | '@original',
|
||||
options: string | MessagePayload | WebhookEditMessageOptions,
|
||||
): Promise<Message>;
|
||||
public fetchMessage(message: string): Promise<Message>;
|
||||
public fetchMessage(message: Snowflake | '@original'): Promise<Message>;
|
||||
}
|
||||
|
||||
export class Invite extends Base {
|
||||
@@ -2804,6 +2804,13 @@ export class Webhook extends WebhookMixin() {
|
||||
applicationId: null;
|
||||
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) {
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
APITextInputComponent,
|
||||
APIEmbed,
|
||||
ApplicationCommandType,
|
||||
APIMessage,
|
||||
} from 'discord-api-types/v10';
|
||||
import {
|
||||
ApplicationCommand,
|
||||
@@ -130,6 +131,9 @@ import {
|
||||
ThreadMemberManager,
|
||||
CollectedMessageInteraction,
|
||||
ShardEvents,
|
||||
Webhook,
|
||||
WebhookClient,
|
||||
InteractionWebhook,
|
||||
} from '.';
|
||||
import { expectAssignable, expectNotAssignable, expectNotType, expectType } from 'tsd';
|
||||
import type { ContextMenuCommandBuilder, SlashCommandBuilder } from '@discordjs/builders';
|
||||
@@ -1691,3 +1695,20 @@ expectType<ChannelMention>(partialGroupDMChannel.toString());
|
||||
expectType<UserMention>(dmChannel.toString());
|
||||
expectType<UserMention>(user.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));
|
||||
|
||||
Reference in New Issue
Block a user