Skip to content

Instantly share code, notes, and snippets.

@insyri
Created March 22, 2021 12:05
Show Gist options
  • Save insyri/95dd8205abf57aef6efcab911eb7fc86 to your computer and use it in GitHub Desktop.
Save insyri/95dd8205abf57aef6efcab911eb7fc86 to your computer and use it in GitHub Desktop.
function endSession(message, reason) {
var newembed = new Discord.MessageEmbed()
newembed.setDescription(`Session ended (${reason}).`)
newembed.setColor(0xd90479)
message.edit(newembed)
}
function completeSession(message, reason) {
var newembed = new Discord.MessageEmbed()
newembed.setDescription(reason)
newembed.setColor(0xd90479)
message.edit(newembed)
}
//first send the are you sure prompt
var prompt = await message.channel.send("are you sure you wanna do this?");
const filter = m => m.author.id === message.author.id;
message.channel.awaitMessages(filter, { max: 1, time: 10000 , errors: ['time'] }).then(async(collected) => {
switch(collected.some(message => message.content == 'yes'|| message.content == 'no')){
case collected.some(message => message.content == 'yes'):
try {
await /*do something here*/.then(() => completeSession(prompt, `Done! It was successful.`))
} catch(err) {
completeSession(prompt, `Failed command, see console logs.`)
console.error(err);
}
return;
break;
case collected.some(message => message.content == 'n'):
completeSession(prompt, `Canceled command on request`))
return;
break;
default:
endSession(prompt, "Invalid response");
return;
}
}).catch((err) => {
endSession(prompt, `Timed out`)
console.error(err)
})
//this is really inconsitent so its probably better done somehow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment