mirror of
https://github.com/danbulant/discord.js
synced 2026-05-24 20:42:27 +00:00
Add awaitMessages
This commit is contained in:
parent
91b1fa8359
commit
ff3148ddd4
5 changed files with 44 additions and 1 deletions
File diff suppressed because one or more lines are too long
|
|
@ -74,6 +74,10 @@ class DMChannel extends Channel {
|
|||
createCollector() {
|
||||
return;
|
||||
}
|
||||
|
||||
awaitMessages() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
TextBasedChannel.applyToClass(DMChannel, true);
|
||||
|
|
|
|||
|
|
@ -151,6 +151,10 @@ class GroupDMChannel extends Channel {
|
|||
createCollector() {
|
||||
return;
|
||||
}
|
||||
|
||||
awaitMessages() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
TextBasedChannel.applyToClass(GroupDMChannel, true);
|
||||
|
|
|
|||
|
|
@ -59,6 +59,10 @@ class TextChannel extends GuildChannel {
|
|||
createCollector() {
|
||||
return;
|
||||
}
|
||||
|
||||
awaitMessages() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
TextBasedChannel.applyToClass(TextChannel, true);
|
||||
|
|
|
|||
|
|
@ -288,6 +288,36 @@ class TextBasedChannel {
|
|||
return collector;
|
||||
}
|
||||
|
||||
/**
|
||||
* An object containing the same properties as CollectorOptions, but a few more:
|
||||
* ```js
|
||||
* {
|
||||
* errors: [], // an array of stop/end reasons that cause the promise to reject.
|
||||
* }
|
||||
* ```
|
||||
* @typedef {Object} AwaitMessagesOptions
|
||||
*/
|
||||
|
||||
/**
|
||||
* Similar to createCollector but in Promise form. Resolves with a Collection of messages that pass the specified
|
||||
* filter.
|
||||
* @param {CollectorFilterFunction} filter the filter function to use
|
||||
* @param {AwaitMessagesOptions} [options={}] optional options to pass to the internal collector
|
||||
* @returns {Promise<Collection<String, Message>>}
|
||||
*/
|
||||
awaitMessages(filter, options = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const collector = this.createCollector(filter, options);
|
||||
collector.on('end', (collection, reason) => {
|
||||
if (options.errors && options.errors.includes(reason)) {
|
||||
reject(collection);
|
||||
} else {
|
||||
resolve(collection);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
_cacheMessage(message) {
|
||||
const maxSize = this.client.options.max_message_cache;
|
||||
if (maxSize === 0) {
|
||||
|
|
@ -338,6 +368,7 @@ exports.applyToClass = (structure, full = false) => {
|
|||
props.push('setTyping');
|
||||
props.push('fetchPinnedMessages');
|
||||
props.push('createCollector');
|
||||
props.push('awaitMessages');
|
||||
}
|
||||
for (const prop of props) {
|
||||
applyProp(structure, prop);
|
||||
|
|
|
|||
Loading…
Reference in a new issue