mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 00:23:30 +01:00
refactor: rewrite message creation (#2774)
* Rework createMessage - MessageAttachment is now structurally similar to FileOptions - No longer mutates the object passed as options - Supports more permutations of arguments * Ignore complexity warning * Refactor name finding * Fix typo * Update typings * Default name to null for MessageAttachment * Make Message#reply use transformOptions * Move transformOptions * Fix Message#reply * Fix mutation * Update tests * Fix options passing * Refactor into APIMessage * Fix webhook send * Expose APIMessage * Add documentation * Add types * Fix type doc * Fix another type doc * Fix another another type doc (is this one even right!?) * Remove trailing comma * Properly clone split options * Add support for sending file as stream * Missed a doc * Resolve files only once when splitting messages * This looks nicer * Assign directly * Don't cache data and files * Missing return type * Use object spread instead Object.assign * Document constructors * Crawl is a little dot * comp pls * tests: sanitize local file path, disable no-await-in-loop
This commit is contained in:
@@ -10,7 +10,7 @@ const { MessageTypes } = require('../util/Constants');
|
||||
const Permissions = require('../util/Permissions');
|
||||
const Base = require('./Base');
|
||||
const { Error, TypeError } = require('../errors');
|
||||
const { createMessage } = require('./shared');
|
||||
const APIMessage = require('./APIMessage');
|
||||
|
||||
/**
|
||||
* Represents a message on Discord.
|
||||
@@ -359,7 +359,7 @@ class Message extends Base {
|
||||
|
||||
/**
|
||||
* Edits the content of the message.
|
||||
* @param {StringResolvable} [content] The new content for the message
|
||||
* @param {StringResolvable} [content=''] The new content for the message
|
||||
* @param {MessageEditOptions|MessageEmbed} [options] The options to provide
|
||||
* @returns {Promise<Message>}
|
||||
* @example
|
||||
@@ -368,17 +368,8 @@ class Message extends Base {
|
||||
* .then(msg => console.log(`Updated the content of a message to ${msg.content}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
async edit(content, options) {
|
||||
if (!options && typeof content === 'object' && !(content instanceof Array)) {
|
||||
options = content;
|
||||
content = null;
|
||||
} else if (!options) {
|
||||
options = {};
|
||||
}
|
||||
if (!options.content) options.content = content;
|
||||
|
||||
const { data } = await createMessage(this, options);
|
||||
|
||||
edit(content, options) {
|
||||
const data = APIMessage.create(this, content, options).resolveData();
|
||||
return this.client.api.channels[this.channel.id].messages[this.id]
|
||||
.patch({ data })
|
||||
.then(d => {
|
||||
@@ -467,8 +458,8 @@ class Message extends Base {
|
||||
|
||||
/**
|
||||
* Replies to the message.
|
||||
* @param {StringResolvable} [content] The content for the message
|
||||
* @param {MessageOptions} [options] The options to provide
|
||||
* @param {StringResolvable} [content=''] The content for the message
|
||||
* @param {MessageOptions|MessageAdditions} [options={}] The options to provide
|
||||
* @returns {Promise<Message|Message[]>}
|
||||
* @example
|
||||
* // Reply to a message
|
||||
@@ -477,13 +468,7 @@ class Message extends Base {
|
||||
* .catch(console.error);
|
||||
*/
|
||||
reply(content, options) {
|
||||
if (!options && typeof content === 'object' && !(content instanceof Array)) {
|
||||
options = content;
|
||||
content = '';
|
||||
} else if (!options) {
|
||||
options = {};
|
||||
}
|
||||
return this.channel.send(content, Object.assign(options, { reply: this.member || this.author }));
|
||||
return this.channel.send(APIMessage.transformOptions(content, options, { reply: this.member || this.author }));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user