Skip to content

Commit

Permalink
fix(Message): editing with MessageEmbed or APIMessage (#5612)
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceEEC committed May 11, 2021
1 parent 2eac842 commit 74e97ef
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/managers/MessageManager.js
Expand Up @@ -117,14 +117,14 @@ class MessageManager extends BaseManager {
/**
* Edits a message, even if it's not cached.
* @param {MessageResolvable} message The message to edit
* @param {MessageEditOptions} [options] The options to provide
* @param {MessageEditOptions|APIMessage} [options] The options to provide
* @returns {Promise<Message>}
*/
async edit(message, options) {
message = this.resolveID(message);
if (!message) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable');

const { data } = APIMessage.create(this, options).resolveData();
const { data } = (options instanceof APIMessage ? options : APIMessage.create(this, options)).resolveData();
const d = await this.client.api.channels[this.channel.id].messages[message].patch({ data });

if (this.cache.has(message)) {
Expand Down
7 changes: 2 additions & 5 deletions src/structures/Message.js
Expand Up @@ -494,11 +494,8 @@ class Message extends Base {
* .catch(console.error);
*/
edit(content, options) {
if (!options && typeof content === 'object' && !Array.isArray(content)) {
options = content;
content = undefined;
}
return this.channel.messages.edit(this.id, { content, ...options });
options = content instanceof APIMessage ? content : APIMessage.create(this.channel, content, options);
return this.channel.messages.edit(this.id, options);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion typings/index.d.ts
Expand Up @@ -2193,7 +2193,7 @@ declare module 'discord.js' {
public cache: Collection<Snowflake, Message>;
public crosspost(message: MessageResolvable): Promise<Message>;
public delete(message: MessageResolvable): Promise<void>;
public edit(message: MessageResolvable, options: MessageEditOptions): Promise<Message>;
public edit(message: MessageResolvable, options: APIMessage | MessageEditOptions): Promise<Message>;
public fetch(message: Snowflake, cache?: boolean, force?: boolean): Promise<Message>;
public fetch(
options?: ChannelLogsQueryOptions,
Expand Down

0 comments on commit 74e97ef

Please sign in to comment.