refactor: enforce single param on sending/editing methods (#5758)

Co-authored-by: ckohen <chaikohen@gmail.com>
Co-authored-by: Jan <66554238+vaporox@users.noreply.github.com>
Co-authored-by: SpaceEEC <spaceeec@yahoo.com>
This commit is contained in:
Adrian Castro
2021-06-09 14:12:16 +02:00
committed by GitHub
parent dda5ee2e9f
commit 0467a9075f
8 changed files with 89 additions and 260 deletions

View File

@@ -544,8 +544,7 @@ class Message extends Base {
/**
* Edits the content of the message.
* @param {?(string|APIMessage)} [content] The new content for the message
* @param {MessageEditOptions|MessageEmbed|MessageAttachment|MessageAttachment[]} [options] The options to provide
* @param {string|APIMessage|MessageEditOptions} options The options to provide
* @returns {Promise<Message>}
* @example
* // Update the content of a message
@@ -553,8 +552,7 @@ class Message extends Base {
* .then(msg => console.log(`Updated the content of a message to ${msg.content}`))
* .catch(console.error);
*/
edit(content, options) {
options = content instanceof APIMessage ? content : APIMessage.create(this, content, options);
edit(options) {
return this.channel.messages.edit(this.id, options);
}
@@ -650,8 +648,7 @@ class Message extends Base {
/**
* Send an inline reply to this message.
* @param {string|APIMessage} [content=''] The content for the message
* @param {ReplyMessageOptions|MessageAdditions} [options] The additional options to provide
* @param {string|APIMessage|ReplyMessageOptions} options The options to provide
* @returns {Promise<Message|Message[]>}
* @example
* // Reply to a message
@@ -659,17 +656,20 @@ class Message extends Base {
* .then(() => console.log(`Replied to message "${message.content}"`))
* .catch(console.error);
*/
reply(content, options) {
return this.channel.send(
content instanceof APIMessage
? content
: APIMessage.transformOptions(content, options, {
reply: {
messageReference: this,
failIfNotExists: options?.failIfNotExists ?? content?.failIfNotExists ?? true,
},
}),
);
reply(options) {
let data;
if (options instanceof APIMessage) {
data = options;
} else {
data = APIMessage.create(this, options, {
reply: {
messageReference: this,
failIfNotExists: options?.failIfNotExists ?? true,
},
});
}
return this.channel.send(data);
}
/**