mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 03:23:29 +01:00
Add awaitMessages
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -74,6 +74,10 @@ class DMChannel extends Channel {
|
|||||||
createCollector() {
|
createCollector() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
awaitMessages() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TextBasedChannel.applyToClass(DMChannel, true);
|
TextBasedChannel.applyToClass(DMChannel, true);
|
||||||
|
|||||||
@@ -151,6 +151,10 @@ class GroupDMChannel extends Channel {
|
|||||||
createCollector() {
|
createCollector() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
awaitMessages() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TextBasedChannel.applyToClass(GroupDMChannel, true);
|
TextBasedChannel.applyToClass(GroupDMChannel, true);
|
||||||
|
|||||||
@@ -59,6 +59,10 @@ class TextChannel extends GuildChannel {
|
|||||||
createCollector() {
|
createCollector() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
awaitMessages() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TextBasedChannel.applyToClass(TextChannel, true);
|
TextBasedChannel.applyToClass(TextChannel, true);
|
||||||
|
|||||||
@@ -288,6 +288,36 @@ class TextBasedChannel {
|
|||||||
return collector;
|
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) {
|
_cacheMessage(message) {
|
||||||
const maxSize = this.client.options.max_message_cache;
|
const maxSize = this.client.options.max_message_cache;
|
||||||
if (maxSize === 0) {
|
if (maxSize === 0) {
|
||||||
@@ -338,6 +368,7 @@ exports.applyToClass = (structure, full = false) => {
|
|||||||
props.push('setTyping');
|
props.push('setTyping');
|
||||||
props.push('fetchPinnedMessages');
|
props.push('fetchPinnedMessages');
|
||||||
props.push('createCollector');
|
props.push('createCollector');
|
||||||
|
props.push('awaitMessages');
|
||||||
}
|
}
|
||||||
for (const prop of props) {
|
for (const prop of props) {
|
||||||
applyProp(structure, prop);
|
applyProp(structure, prop);
|
||||||
|
|||||||
Reference in New Issue
Block a user