mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 00:53:31 +01:00
refactor(MessagePayload): rename APIMessage (#5921)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const APIMessage = require('./APIMessage');
|
||||
const Channel = require('./Channel');
|
||||
const MessagePayload = require('./MessagePayload');
|
||||
const { Error } = require('../errors');
|
||||
const { WebhookTypes } = require('../util/Constants');
|
||||
const DataResolver = require('../util/DataResolver');
|
||||
@@ -109,8 +109,8 @@ class Webhook {
|
||||
|
||||
/**
|
||||
* Sends a message with this webhook.
|
||||
* @param {string|APIMessage|WebhookMessageOptions} options The options to provide
|
||||
* @returns {Promise<Message|APIMessageRaw>}
|
||||
* @param {string|MessagePayload|WebhookMessageOptions} options The options to provide
|
||||
* @returns {Promise<Message|APIMessage>}
|
||||
* @example
|
||||
* // Send a basic message
|
||||
* webhook.send('hello!')
|
||||
@@ -158,21 +158,21 @@ class Webhook {
|
||||
async send(options) {
|
||||
if (!this.token) throw new Error('WEBHOOK_TOKEN_UNAVAILABLE');
|
||||
|
||||
let apiMessage;
|
||||
let messagePayload;
|
||||
|
||||
if (options instanceof APIMessage) {
|
||||
apiMessage = options.resolveData();
|
||||
if (options instanceof MessagePayload) {
|
||||
messagePayload = options.resolveData();
|
||||
} else {
|
||||
apiMessage = APIMessage.create(this, options).resolveData();
|
||||
messagePayload = MessagePayload.create(this, options).resolveData();
|
||||
}
|
||||
|
||||
const { data, files } = await apiMessage.resolveFiles();
|
||||
const { data, files } = await messagePayload.resolveFiles();
|
||||
return this.client.api
|
||||
.webhooks(this.id, this.token)
|
||||
.post({
|
||||
data,
|
||||
files,
|
||||
query: { thread_id: apiMessage.options.threadID, wait: true },
|
||||
query: { thread_id: messagePayload.options.threadID, wait: true },
|
||||
auth: false,
|
||||
})
|
||||
.then(d => {
|
||||
@@ -247,7 +247,7 @@ class Webhook {
|
||||
* Gets a message that was sent by this webhook.
|
||||
* @param {Snowflake|'@original'} message The ID of the message to fetch
|
||||
* @param {boolean} [cache=true] Whether to cache the message
|
||||
* @returns {Promise<Message|APIMessageRaw>} Returns the raw message data if the webhook was instantiated as a
|
||||
* @returns {Promise<Message|APIMessage>} Returns the raw message data if the webhook was instantiated as a
|
||||
* {@link WebhookClient} or if the channel is uncached, otherwise a {@link Message} will be returned
|
||||
*/
|
||||
async fetchMessage(message, cache = true) {
|
||||
@@ -260,19 +260,19 @@ class Webhook {
|
||||
/**
|
||||
* Edits a message that was sent by this webhook.
|
||||
* @param {MessageResolvable|'@original'} message The message to edit
|
||||
* @param {string|APIMessage|WebhookEditMessageOptions} options The options to provide
|
||||
* @returns {Promise<Message|APIMessageRaw>} Returns the raw message data if the webhook was instantiated as a
|
||||
* @param {string|MessagePayload|WebhookEditMessageOptions} options The options to provide
|
||||
* @returns {Promise<Message|APIMessage>} Returns the raw message data if the webhook was instantiated as a
|
||||
* {@link WebhookClient} or if the channel is uncached, otherwise a {@link Message} will be returned
|
||||
*/
|
||||
async editMessage(message, options) {
|
||||
if (!this.token) throw new Error('WEBHOOK_TOKEN_UNAVAILABLE');
|
||||
|
||||
let apiMessage;
|
||||
let messagePayload;
|
||||
|
||||
if (options instanceof APIMessage) apiMessage = options;
|
||||
else apiMessage = APIMessage.create(this, options);
|
||||
if (options instanceof MessagePayload) messagePayload = options;
|
||||
else messagePayload = MessagePayload.create(this, options);
|
||||
|
||||
const { data, files } = await apiMessage.resolveData().resolveFiles();
|
||||
const { data, files } = await messagePayload.resolveData().resolveFiles();
|
||||
|
||||
const d = await this.client.api
|
||||
.webhooks(this.id, this.token)
|
||||
|
||||
Reference in New Issue
Block a user