mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 17:13:31 +01:00
feat(MessageManager): extend API coverage (#4869)
Co-authored-by: Sugden <28943913+NotSugden@users.noreply.github.com> Co-authored-by: izexi <43889168+izexi@users.noreply.github.com> Co-authored-by: Advaith <advaithj1@gmail.com>
This commit is contained in:
@@ -8,7 +8,7 @@ const Embed = require('./MessageEmbed');
|
||||
const Mentions = require('./MessageMentions');
|
||||
const ReactionCollector = require('./ReactionCollector');
|
||||
const Sticker = require('./Sticker');
|
||||
const { Error, TypeError } = require('../errors');
|
||||
const { Error } = require('../errors');
|
||||
const ReactionManager = require('../managers/ReactionManager');
|
||||
const Collection = require('../util/Collection');
|
||||
const { InteractionTypes, MessageTypes, SystemMessageTypes } = require('../util/Constants');
|
||||
@@ -472,7 +472,7 @@ class Message extends Base {
|
||||
}
|
||||
|
||||
/**
|
||||
* Options that can be passed into editMessage.
|
||||
* Options that can be passed into {@link Message#edit}.
|
||||
* @typedef {Object} MessageEditOptions
|
||||
* @property {string} [content] Content to be edited
|
||||
* @property {MessageEmbed|Object} [embed] An embed to be added/edited
|
||||
@@ -494,13 +494,11 @@ class Message extends Base {
|
||||
* .catch(console.error);
|
||||
*/
|
||||
edit(content, options) {
|
||||
const { data } =
|
||||
content instanceof APIMessage ? content.resolveData() : APIMessage.create(this, content, options).resolveData();
|
||||
return this.client.api.channels[this.channel.id].messages[this.id].patch({ data }).then(d => {
|
||||
const clone = this._clone();
|
||||
clone._patch(d);
|
||||
return clone;
|
||||
});
|
||||
if (!options && typeof content === 'object' && !Array.isArray(content)) {
|
||||
options = content;
|
||||
content = undefined;
|
||||
}
|
||||
return this.channel.messages.edit(this.id, { content, ...options });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -514,47 +512,34 @@ class Message extends Base {
|
||||
* .catch(console.error);
|
||||
* }
|
||||
*/
|
||||
async crosspost() {
|
||||
await this.client.api.channels(this.channel.id).messages(this.id).crosspost.post();
|
||||
return this;
|
||||
crosspost() {
|
||||
return this.channel.messages.crosspost(this.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pins this message to the channel's pinned messages.
|
||||
* @param {Object} [options] Options for pinning
|
||||
* @param {string} [options.reason] Reason for pinning
|
||||
* @returns {Promise<Message>}
|
||||
* @example
|
||||
* // Pin a message with a reason
|
||||
* message.pin({ reason: 'important' })
|
||||
* // Pin a message
|
||||
* message.pin()
|
||||
* .then(console.log)
|
||||
* .catch(console.error)
|
||||
*/
|
||||
pin(options) {
|
||||
return this.client.api
|
||||
.channels(this.channel.id)
|
||||
.pins(this.id)
|
||||
.put(options)
|
||||
.then(() => this);
|
||||
pin() {
|
||||
return this.channel.messages.pin(this.id).then(() => this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unpins this message from the channel's pinned messages.
|
||||
* @param {Object} [options] Options for unpinning
|
||||
* @param {string} [options.reason] Reason for unpinning
|
||||
* @returns {Promise<Message>}
|
||||
* @example
|
||||
* // Unpin a message with a reason
|
||||
* message.unpin({ reason: 'no longer relevant' })
|
||||
* // Unpin a message
|
||||
* message.unpin()
|
||||
* .then(console.log)
|
||||
* .catch(console.error)
|
||||
*/
|
||||
unpin(options) {
|
||||
return this.client.api
|
||||
.channels(this.channel.id)
|
||||
.pins(this.id)
|
||||
.delete(options)
|
||||
.then(() => this);
|
||||
unpin() {
|
||||
return this.channel.messages.unpin(this.id).then(() => this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -572,24 +557,14 @@ class Message extends Base {
|
||||
* .then(console.log)
|
||||
* .catch(console.error);
|
||||
*/
|
||||
react(emoji) {
|
||||
emoji = this.client.emojis.resolveIdentifier(emoji);
|
||||
if (!emoji) throw new TypeError('EMOJI_TYPE');
|
||||
|
||||
return this.client.api
|
||||
.channels(this.channel.id)
|
||||
.messages(this.id)
|
||||
.reactions(emoji, '@me')
|
||||
.put()
|
||||
.then(
|
||||
() =>
|
||||
this.client.actions.MessageReactionAdd.handle({
|
||||
user: this.client.user,
|
||||
channel: this.channel,
|
||||
message: this,
|
||||
emoji: Util.parseEmoji(emoji),
|
||||
}).reaction,
|
||||
);
|
||||
async react(emoji) {
|
||||
await this.channel.messages.react(this.id, emoji);
|
||||
return this.client.actions.MessageReactionAdd.handle({
|
||||
user: this.client.user,
|
||||
channel: this.channel,
|
||||
message: this,
|
||||
emoji: Util.parseEmoji(emoji),
|
||||
}).reaction;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user