fix(Message): editing with MessageEmbed or APIMessage (#5612)

This commit is contained in:
SpaceEEC
2021-05-11 22:22:48 +02:00
committed by GitHub
parent 2eac84296b
commit 74e97ef91b
3 changed files with 5 additions and 8 deletions

View File

@@ -117,14 +117,14 @@ class MessageManager extends BaseManager {
/** /**
* Edits a message, even if it's not cached. * Edits a message, even if it's not cached.
* @param {MessageResolvable} message The message to edit * @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>} * @returns {Promise<Message>}
*/ */
async edit(message, options) { async edit(message, options) {
message = this.resolveID(message); message = this.resolveID(message);
if (!message) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable'); 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 }); const d = await this.client.api.channels[this.channel.id].messages[message].patch({ data });
if (this.cache.has(message)) { if (this.cache.has(message)) {

View File

@@ -494,11 +494,8 @@ class Message extends Base {
* .catch(console.error); * .catch(console.error);
*/ */
edit(content, options) { edit(content, options) {
if (!options && typeof content === 'object' && !Array.isArray(content)) { options = content instanceof APIMessage ? content : APIMessage.create(this.channel, content, options);
options = content; return this.channel.messages.edit(this.id, options);
content = undefined;
}
return this.channel.messages.edit(this.id, { content, ...options });
} }
/** /**

2
typings/index.d.ts vendored
View File

@@ -2193,7 +2193,7 @@ declare module 'discord.js' {
public cache: Collection<Snowflake, Message>; public cache: Collection<Snowflake, Message>;
public crosspost(message: MessageResolvable): Promise<Message>; public crosspost(message: MessageResolvable): Promise<Message>;
public delete(message: MessageResolvable): Promise<void>; 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(message: Snowflake, cache?: boolean, force?: boolean): Promise<Message>;
public fetch( public fetch(
options?: ChannelLogsQueryOptions, options?: ChannelLogsQueryOptions,