Added message collector

merge-requests/1/merge
Bsian 2019-10-27 15:15:13 +00:00
parent 99a9a3911d
commit bc37ac49f3
No known key found for this signature in database
GPG Key ID: 097FB9A291026091
1 changed files with 12 additions and 0 deletions

View File

@ -127,4 +127,16 @@ export default class Util {
await log.save(); await log.save();
await account.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); }
});
});
}
} }