Added message collector
parent
99a9a3911d
commit
bc37ac49f3
12
src/Util.ts
12
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); }
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue