mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 17:13:31 +01:00
feat(Message|TextChannel): Inline replies (#4874)
* feat(Message): remove reply functionality * feat(InlineReplies): add INLINE_REPLY constant/typing * feat(InlineReplies): add Message#replyReference property * feat(InlineReplies): add typings for sending inline replies * feat(InlineReplies): provide support for inline-replying to messages * feat(Message): add referencedMessage getter * fix: check that Message#reference is defined in referencedMessage * refactor(InlineReplies): rename property, rework Message resolution * docs: update jsdoc for inline replies * feat(Message): inline reply method * fix(ApiMessage): finish renaming replyTo * fix: jsdocs for Message#referencedMessage Co-authored-by: Tristan Guichaoua <33934311+tguichaoua@users.noreply.github.com> * fix: restore reply typings * fix: dont pass channel_id to API when replying * chore: update jsdocs * chore: more jsdoc updates * feat(AllowedMentions): add typings for replied_user * fix: naming conventions * fix(Message): referenced_message is null, not undefined * fix(MessageMentionOptions): repliedUser should be optional * chore: get this back to the right state * fix(ApiMessage): pass allowed_mentions when replying without content * fix(ApiMessage): prevent mutation of client options Co-authored-by: almostSouji <timoqueezle@gmail.com> Co-authored-by: Tristan Guichaoua <33934311+tguichaoua@users.noreply.github.com>
This commit is contained in:
@@ -205,11 +205,11 @@ class Message extends Base {
|
||||
this.flags = new MessageFlags(data.flags).freeze();
|
||||
|
||||
/**
|
||||
* Reference data sent in a crossposted message.
|
||||
* Reference data sent in a crossposted message or inline reply.
|
||||
* @typedef {Object} MessageReference
|
||||
* @property {string} channelID ID of the channel the message was crossposted from
|
||||
* @property {?string} guildID ID of the guild the message was crossposted from
|
||||
* @property {?string} messageID ID of the message that was crossposted
|
||||
* @property {string} channelID ID of the channel the message was referenced
|
||||
* @property {?string} guildID ID of the guild the message was referenced
|
||||
* @property {?string} messageID ID of the message that was referenced
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -223,6 +223,10 @@ class Message extends Base {
|
||||
messageID: data.message_reference.message_id,
|
||||
}
|
||||
: null;
|
||||
|
||||
if (data.referenced_message) {
|
||||
this.channel.messages.add(data.referenced_message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -425,6 +429,18 @@ class Message extends Base {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The Message this crosspost/reply/pin-add references, if cached
|
||||
* @type {?Message}
|
||||
* @readonly
|
||||
*/
|
||||
get referencedMessage() {
|
||||
if (!this.reference) return null;
|
||||
const referenceChannel = this.client.channels.resolve(this.reference.channelID);
|
||||
if (!referenceChannel) return null;
|
||||
return referenceChannel.messages.resolve(this.reference.messageID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the message is crosspostable by the client user
|
||||
* @type {boolean}
|
||||
@@ -588,21 +604,19 @@ class Message extends Base {
|
||||
}
|
||||
|
||||
/**
|
||||
* Replies to the message.
|
||||
* Send an inline reply to this message.
|
||||
* @param {StringResolvable|APIMessage} [content=''] The content for the message
|
||||
* @param {MessageOptions|MessageAdditions} [options={}] The options to provide
|
||||
* @param {MessageOptions|MessageAdditions} [options] The additional options to provide
|
||||
* @param {MessageResolvable} [options.replyTo=this] The message to reply to
|
||||
* @returns {Promise<Message|Message[]>}
|
||||
* @example
|
||||
* // Reply to a message
|
||||
* message.reply('Hey, I\'m a reply!')
|
||||
* .then(() => console.log(`Sent a reply to ${message.author.username}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
reply(content, options) {
|
||||
return this.channel.send(
|
||||
content instanceof APIMessage
|
||||
? content
|
||||
: APIMessage.transformOptions(content, options, { reply: this.member || this.author }),
|
||||
: APIMessage.transformOptions(content, options, {
|
||||
replyTo: this,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user