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); } + }); + }); + } }