From 2666a9d6dbb6596b5893e7fbdb57c1d907a1ab6b Mon Sep 17 00:00:00 2001 From: bdistin Date: Mon, 29 Apr 2019 11:53:32 -0500 Subject: [PATCH] feat(MessageStore): add remove() (#2468) * MessageStore#remove() * typings --- src/stores/MessageStore.js | 10 ++++++++++ src/structures/Message.js | 12 +++++------- typings/index.d.ts | 1 + 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/stores/MessageStore.js b/src/stores/MessageStore.js index db72114f6..e179daa21 100644 --- a/src/stores/MessageStore.js +++ b/src/stores/MessageStore.js @@ -82,6 +82,16 @@ class MessageStore extends DataStore { }); } + /** + * 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 + */ + async remove(message, reason) { + message = this.resolveID(message); + if (message) await this.client.api.channels(this.channel.id).messages(message).delete({ reason }); + } + async _fetchId(messageID, cache) { const existing = this.get(messageID); if (existing && !existing.partial) return existing; diff --git a/src/structures/Message.js b/src/structures/Message.js index b57f4299e..c390ac231 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -454,13 +454,11 @@ class Message extends Base { */ delete({ timeout = 0, reason } = {}) { if (timeout <= 0) { - return this.client.api.channels(this.channel.id).messages(this.id) - .delete({ reason }) - .then(() => - this.client.actions.MessageDelete.handle({ - id: this.id, - channel_id: this.channel.id, - }).message); + return this.channel.messages.remove(this.id, reason).then(() => + this.client.actions.MessageDelete.handle({ + id: this.id, + channel_id: this.channel.id, + }).message); } else { return new Promise(resolve => { this.client.setTimeout(() => { diff --git a/typings/index.d.ts b/typings/index.d.ts index 4a57b1ec9..1186be6ed 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1448,6 +1448,7 @@ declare module 'discord.js' { public fetch(message: Snowflake, cache?: boolean): Promise; public fetch(options?: ChannelLogsQueryOptions, cache?: boolean): Promise>; public fetchPinned(cache?: boolean): Promise>; + public remove(message: MessageResolvable, reason?: string): Promise; } export class PresenceStore extends DataStore {