Adds a prefix command `!destruct <message>` that will display the message with a countdown before deleting it entirely after a few seconds.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const sleep = async ms => new Promise(r => setTimeout(r, ms))
const event = context.params.event;
// ** Dev ** configure variables
const command = '!destruct';
const seconds = 5;
// Is this our command?
if (!event.content.startsWith(command)) return
const channel_id = event.channel_id
const content = event.content.replace(command, '').trim()
// Delete original (because we can't update it)
await lib.discord.channels['@0.2.0'].messages.destroy({
message_id: event.id,
channel_id,
});
// Create new new message
const message = await lib.discord.channels['@0.2.0'].messages.create({
channel_id, content: `(${seconds}) ${content}`
});
const message_id = message.id
// Countdown and update message
for (let i = seconds; i > 0; i--) {
await lib.discord.channels['@0.2.0'].messages.update({
message_id, channel_id,
content: `(${i}) ${content}`
});
await sleep(1000)
}
// Destrcut!
await lib.discord.channels['@0.2.0'].messages.destroy({
message_id,
channel_id,
});