forked from discordjs/discord.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InteractionResponse.js
58 lines (53 loc) · 1.82 KB
/
InteractionResponse.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
'use strict';
const { InteractionType } = require('discord-api-types/v10');
const { Error, ErrorCodes } = require('../errors');
/**
* Represents an interaction's response
*/
class InteractionResponse {
constructor(interaction, id) {
/**
* The interaction associated with the interaction response
* @type {BaseInteraction}
*/
this.interaction = interaction;
/**
* The id of the original interaction response
* @type {Snowflake}
*/
this.id = id ?? interaction.id;
this.client = interaction.client;
}
/**
* Collects a single component interaction that passes the filter.
* The Promise will reject if the time expires.
* @param {AwaitMessageComponentOptions} [options={}] Options to pass to the internal collector
* @returns {Promise<MessageComponentInteraction>}
*/
awaitMessageComponent(options = {}) {
const _options = { ...options, max: 1 };
return new Promise((resolve, reject) => {
const collector = this.createMessageComponentCollector(_options);
collector.once('end', (interactions, reason) => {
const interaction = interactions.first();
if (interaction) resolve(interaction);
else reject(new Error(ErrorCodes.InteractionCollectorError, reason));
});
});
}
/**
* Creates a message component interaction collector
* @param {MessageComponentCollectorOptions} [options={}] Options to send to the collector
* @returns {InteractionCollector}
*/
createMessageComponentCollector(options = {}) {
return new InteractionCollector(this.client, {
...options,
interactionResponse: this,
interactionType: InteractionType.MessageComponent,
});
}
}
// eslint-disable-next-line import/order
const InteractionCollector = require('./InteractionCollector');
module.exports = InteractionResponse;