move prompt interaction to invokerwrapper

This commit is contained in:
Erik 2022-09-06 13:11:35 +03:00
parent 8b2c25085b
commit a5d0479d4e
Signed by untrusted user: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
2 changed files with 37 additions and 17 deletions

View File

@ -69,24 +69,24 @@ class InteractionWrapper {
return this.interaction.editReply(options);
}
async promptInteraction(opts = {}, time = 30) {
if (!opts.components) throw new Error('Missing components. Use promptMessage');
let message = null;
if (this.replied || this.deferred) message = await this.editReply(opts);
else message = await this.reply(opts);
// async promptInteraction(opts = {}, time = 30) {
// if (!opts.components) throw new Error('Missing components. Use promptMessage');
// let message = null;
// if (this.replied || this.deferred) message = await this.editReply(opts);
// else message = await this.reply(opts);
return new Promise((resolve) => {
message.createMessageComponentCollector({
time: time*1000,
componentType: opts.componentType || 'BUTTON',
max: 1,
filter: (i) => i.user.id === this.user.id
}).on('collect', resolve)
.on('end', (collected) => {
if (!collected.size) resolve(null);
});
});
}
// return new Promise((resolve) => {
// message.createMessageComponentCollector({
// time: time*1000,
// componentType: opts.componentType || 'BUTTON',
// max: 1,
// filter: (i) => i.user.id === this.user.id
// }).on('collect', resolve)
// .on('end', (collected) => {
// if (!collected.size) resolve(null);
// });
// });
// }
replyEmbed(embed) {
if (!embed.color) embed.color = EmbedDefaultColor;

View File

@ -1,4 +1,5 @@
const { EmbedBuilder } = require("@discordjs/builders");
const { ComponentType } = require("discord.js");
const { Emojis, Constants } = require("../../../constants");
const MessageWrapper = require("./MessageWrapper");
@ -135,6 +136,25 @@ class InvokerWrapper {
});
}
async promptInteraction(opts = {}, time = 30) {
if (!opts.components) throw new Error('Missing components. Use promptMessage');
let message = null;
if (this.replied || this.deferred) message = await this.editReply(opts);
else message = await this.reply(opts);
return new Promise((resolve) => {
message.createMessageComponentCollector({
time: time * 1000,
componentType: opts.componentType || ComponentType.Button,
max: 1,
filter: (i) => i.user.id === this.user.id
}).on('collect', resolve)
.on('end', (collected) => {
if (!collected.size) resolve(null);
});
});
}
async reply(options = {}) {
if (typeof options === 'string') options = { content: options };