Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Message): flags not being parsed on some edits #5886

Merged
merged 2 commits into from Jun 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/managers/MessageManager.js
Expand Up @@ -120,16 +120,20 @@ class MessageManager extends BaseManager {
* @returns {Promise<Message>}
*/
async edit(message, options) {
message = this.resolveID(message);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No more mutation, hooray 🧹

if (!message) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable');
const messageID = this.resolveID(message);
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()
.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 clone = this.cache.get(message)._clone();
const existing = this.cache.get(messageID);
if (existing) {
const clone = existing._clone();
clone._patch(d);
return clone;
}
Expand Down
17 changes: 14 additions & 3 deletions src/structures/APIMessage.js
Expand Up @@ -74,6 +74,16 @@ class APIMessage {
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
* @type {boolean}
Expand Down Expand Up @@ -156,9 +166,9 @@ class APIMessage {
}

let flags;
if (this.isMessage) {
if (this.isMessage || this.isMessageManager) {
// 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) {
flags = MessageFlags.FLAGS.EPHEMERAL;
}
Expand Down Expand Up @@ -300,5 +310,6 @@ module.exports = APIMessage;

/**
* 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
*/
2 changes: 1 addition & 1 deletion src/structures/Message.js
Expand Up @@ -559,7 +559,7 @@ class Message extends Base {
* .catch(console.error);
*/
edit(options) {
return this.channel.messages.edit(this.id, options);
return this.channel.messages.edit(this, options);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion typings/index.d.ts
Expand Up @@ -204,6 +204,7 @@ declare module 'discord.js' {
public readonly isUser: boolean;
public readonly isWebhook: boolean;
public readonly isMessage: boolean;
public readonly isMessageManager: boolean;
public readonly isInteraction: boolean;
public files: unknown[] | null;
public options: MessageOptions | WebhookMessageOptions;
Expand Down Expand Up @@ -3556,7 +3557,9 @@ declare module 'discord.js' {
| User
| GuildMember
| Webhook
| WebhookClient;
| WebhookClient
| Message
| MessageManager;

type MessageType =
| 'DEFAULT'
Expand Down