From bc37ac49f3951817fef62ae509cea502332967b8 Mon Sep 17 00:00:00 2001 From: Bsian Date: Sun, 27 Oct 2019 15:15:13 +0000 Subject: [PATCH] Added message collector --- src/Util.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Util.ts b/src/Util.ts index bf34646..3dcaf95 100644 --- a/src/Util.ts +++ b/src/Util.ts @@ -127,4 +127,16 @@ export default class Util { await log.save(); await account.save(); } + + public async messageCollector(message: Message, question: string, timeout: number, shouldDelete = false, choices: string[] = null, filter = (msg: Message): boolean|void => {}) { + const msg = await message.channel.createMessage(question); + return new Promise((res, rej) => { + setTimeout(() => rej(new Error('Did not supply a valid input in time')), timeout); + this.client.on('messageCreate', (Msg) => { + if (filter(Msg) === false) return; + const verif = choices ? choices.includes(Msg.content) : Msg.content; + if (verif) { if (shouldDelete) msg.delete(); res(Msg.content); } + }); + }); + } }