mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 19:43:29 +01:00
fix(Message): flags not being parsed on some edits (#5886)
* fix(Message): flags not being parsed on some edits * refactor(MessageManager): access cache once
This commit is contained in:
@@ -120,16 +120,20 @@ class MessageManager extends BaseManager {
|
|||||||
* @returns {Promise<Message>}
|
* @returns {Promise<Message>}
|
||||||
*/
|
*/
|
||||||
async edit(message, options) {
|
async edit(message, options) {
|
||||||
message = this.resolveID(message);
|
const messageID = this.resolveID(message);
|
||||||
if (!message) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable');
|
if (!messageID) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable');
|
||||||
|
|
||||||
const { data, files } = await (options instanceof APIMessage ? options : APIMessage.create(this, options))
|
const { data, files } = await (options instanceof APIMessage
|
||||||
|
? options
|
||||||
|
: APIMessage.create(message instanceof Message ? message : this, options)
|
||||||
|
)
|
||||||
.resolveData()
|
.resolveData()
|
||||||
.resolveFiles();
|
.resolveFiles();
|
||||||
const d = await this.client.api.channels[this.channel.id].messages[message].patch({ data, files });
|
const d = await this.client.api.channels[this.channel.id].messages[messageID].patch({ data, files });
|
||||||
|
|
||||||
if (this.cache.has(message)) {
|
const existing = this.cache.get(messageID);
|
||||||
const clone = this.cache.get(message)._clone();
|
if (existing) {
|
||||||
|
const clone = existing._clone();
|
||||||
clone._patch(d);
|
clone._patch(d);
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,6 +74,16 @@ class APIMessage {
|
|||||||
return this.target instanceof Message;
|
return this.target instanceof Message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wether or not the target is a message manager
|
||||||
|
* @type {boolean}
|
||||||
|
* @readonly
|
||||||
|
*/
|
||||||
|
get isMessageManager() {
|
||||||
|
const MessageManager = require('../managers/MessageManager');
|
||||||
|
return this.target instanceof MessageManager;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether or not the target is an interaction
|
* Whether or not the target is an interaction
|
||||||
* @type {boolean}
|
* @type {boolean}
|
||||||
@@ -156,9 +166,9 @@ class APIMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let flags;
|
let flags;
|
||||||
if (this.isMessage) {
|
if (this.isMessage || this.isMessageManager) {
|
||||||
// eslint-disable-next-line eqeqeq
|
// eslint-disable-next-line eqeqeq
|
||||||
flags = this.options.flags != null ? new MessageFlags(this.options.flags).bitfield : this.target.flags.bitfield;
|
flags = this.options.flags != null ? new MessageFlags(this.options.flags).bitfield : this.target.flags?.bitfield;
|
||||||
} else if (isInteraction && this.options.ephemeral) {
|
} else if (isInteraction && this.options.ephemeral) {
|
||||||
flags = MessageFlags.FLAGS.EPHEMERAL;
|
flags = MessageFlags.FLAGS.EPHEMERAL;
|
||||||
}
|
}
|
||||||
@@ -300,5 +310,6 @@ module.exports = APIMessage;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A target for a message.
|
* A target for a message.
|
||||||
* @typedef {TextChannel|DMChannel|User|GuildMember|Webhook|WebhookClient|Interaction|InteractionWebhook} MessageTarget
|
* @typedef {TextChannel|DMChannel|User|GuildMember|Webhook|WebhookClient|Interaction|InteractionWebhook|
|
||||||
|
* Message|MessageManager} MessageTarget
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -559,7 +559,7 @@ class Message extends Base {
|
|||||||
* .catch(console.error);
|
* .catch(console.error);
|
||||||
*/
|
*/
|
||||||
edit(options) {
|
edit(options) {
|
||||||
return this.channel.messages.edit(this.id, options);
|
return this.channel.messages.edit(this, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
5
typings/index.d.ts
vendored
5
typings/index.d.ts
vendored
@@ -205,6 +205,7 @@ declare module 'discord.js' {
|
|||||||
public readonly isUser: boolean;
|
public readonly isUser: boolean;
|
||||||
public readonly isWebhook: boolean;
|
public readonly isWebhook: boolean;
|
||||||
public readonly isMessage: boolean;
|
public readonly isMessage: boolean;
|
||||||
|
public readonly isMessageManager: boolean;
|
||||||
public readonly isInteraction: boolean;
|
public readonly isInteraction: boolean;
|
||||||
public files: unknown[] | null;
|
public files: unknown[] | null;
|
||||||
public options: MessageOptions | WebhookMessageOptions;
|
public options: MessageOptions | WebhookMessageOptions;
|
||||||
@@ -3560,7 +3561,9 @@ declare module 'discord.js' {
|
|||||||
| User
|
| User
|
||||||
| GuildMember
|
| GuildMember
|
||||||
| Webhook
|
| Webhook
|
||||||
| WebhookClient;
|
| WebhookClient
|
||||||
|
| Message
|
||||||
|
| MessageManager;
|
||||||
|
|
||||||
type MessageType =
|
type MessageType =
|
||||||
| 'DEFAULT'
|
| 'DEFAULT'
|
||||||
|
|||||||
Reference in New Issue
Block a user