Skip to content

Commit

Permalink
refactor(Message): remove options for Message#delete (#4999)
Browse files Browse the repository at this point in the history
  • Loading branch information
vaporoxx authored Dec 14, 2020
1 parent 4107899 commit 75e6dfb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 22 deletions.
5 changes: 2 additions & 3 deletions src/managers/MessageManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,13 @@ class MessageManager extends BaseManager {
/**
* Deletes a message, even if it's not cached.
* @param {MessageResolvable} message The message to delete
* @param {string} [reason] Reason for deleting this message, if it does not belong to the client user
* @returns {Promise<void>}
*/
async delete(message, reason) {
async delete(message) {
message = this.resolveID(message);
if (!message) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable');

await this.client.api.channels(this.channel.id).messages(message).delete({ reason });
await this.client.api.channels(this.channel.id).messages(message).delete();
}

async _fetchId(messageID, cache, force) {
Expand Down
22 changes: 5 additions & 17 deletions src/structures/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -579,28 +579,16 @@ class Message extends Base {

/**
* Deletes the message.
* @param {Object} [options] Options
* @param {number} [options.timeout=0] How long to wait to delete the message in milliseconds
* @param {string} [options.reason] Reason for deleting this message, if it does not belong to the client user
* @returns {Promise<Message>}
* @example
* // Delete a message
* message.delete({ timeout: 5000 })
* .then(msg => console.log(`Deleted message from ${msg.author.username} after 5 seconds`))
* message.delete()
* .then(msg => console.log(`Deleted message from ${msg.author.username}`))
* .catch(console.error);
*/
delete(options = {}) {
if (typeof options !== 'object') return Promise.reject(new TypeError('INVALID_TYPE', 'options', 'object', true));
const { timeout = 0, reason } = options;
if (timeout <= 0) {
return this.channel.messages.delete(this.id, reason).then(() => this);
} else {
return new Promise(resolve => {
this.client.setTimeout(() => {
resolve(this.delete({ reason }));
}, timeout);
});
}
async delete() {
await this.channel.messages.delete(this.id);
return this;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ declare module 'discord.js' {
options?: AwaitReactionsOptions,
): Promise<Collection<Snowflake, MessageReaction>>;
public createReactionCollector(filter: CollectorFilter, options?: ReactionCollectorOptions): ReactionCollector;
public delete(options?: { timeout?: number; reason?: string }): Promise<Message>;
public delete(): Promise<Message>;
public edit(
content: APIMessageContentResolvable | MessageEditOptions | MessageEmbed | APIMessage,
): Promise<Message>;
Expand Down Expand Up @@ -1978,7 +1978,7 @@ declare module 'discord.js' {
force?: boolean,
): Promise<Collection<Snowflake, Message>>;
public fetchPinned(cache?: boolean): Promise<Collection<Snowflake, Message>>;
public delete(message: MessageResolvable, reason?: string): Promise<void>;
public delete(message: MessageResolvable): Promise<void>;
}

// Hacky workaround because changing the signature of an overridden method errors
Expand Down

1 comment on commit 75e6dfb

@almostSouji
Copy link
Member

@almostSouji almostSouji commented on 75e6dfb Jan 26, 2021

Choose a reason for hiding this comment

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

@ deleted:
You can review the reasoning for applied changes in the respective linked PR, in this case: #4999

Please sign in to comment.