mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 08:33:30 +01:00
Add option to filter old messages in TextBasedChannel#bulkDelete (#1090)
* add filtering for messages older than two weeks * Update RESTMethods.js * Update RESTMethods.js * Update RESTMethods.js * Update TextBasedChannel.js * Update RESTMethods.js * Update RESTMethods.js * Update RESTMethods.js * Update RESTMethods.js * Update TextBasedChannel.js
This commit is contained in:
committed by
Schuyler Cebulskie
parent
78bf402e8e
commit
7f4846c826
@@ -353,16 +353,17 @@ class TextBasedChannel {
|
||||
}
|
||||
|
||||
/**
|
||||
* Bulk delete given messages.
|
||||
* Bulk delete given messages that are newer than two weeks
|
||||
* <warn>This is only available when using a bot account.</warn>
|
||||
* @param {Collection<string, Message>|Message[]|number} messages Messages to delete, or number of messages to delete
|
||||
* @param {boolean} [filterOld=false] Filter messages to remove those which are older than two weeks automatically
|
||||
* @returns {Promise<Collection<string, Message>>} Deleted messages
|
||||
*/
|
||||
bulkDelete(messages) {
|
||||
bulkDelete(messages, filterOld = false) {
|
||||
if (!isNaN(messages)) return this.fetchMessages({ limit: messages }).then(msgs => this.bulkDelete(msgs));
|
||||
if (messages instanceof Array || messages instanceof Collection) {
|
||||
const messageIDs = messages instanceof Collection ? messages.keyArray() : messages.map(m => m.id);
|
||||
return this.client.rest.methods.bulkDeleteMessages(this, messageIDs);
|
||||
return this.client.rest.methods.bulkDeleteMessages(this, messageIDs, filterOld);
|
||||
}
|
||||
throw new TypeError('The messages must be an Array, Collection, or number.');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user