Slash command handler that sends a message that requires a reply within 8 seconds. If nobody replies to the message, deletes the original message. You can adjust the amount of time someone has to reply, but you may need to increase your function timeout under Advanced Settings.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
let sleep = async (ms) => {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
};
let sentMessage = await lib.discord.channels['@0.1.2'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `Reply within 8 seconds or this will be deleted!`
});
await sleep(8000);
let channelMessages = await lib.discord.channels['@0.1.2'].messages.list({
channel_id: `${context.params.event.channel_id}`,
after: `${sentMessage.id}`,
limit: 100
});
let reply = channelMessages.find((channelMessage) => {
return channelMessage.referenced_message.id === sentMessage.id;
});
if (!reply) {
await lib.discord.channels['@0.1.2'].messages.destroy({
message_id: `${sentMessage.id}`,
channel_id: `${context.params.event.channel_id}`
});
await lib.discord.channels['@0.1.2'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `No reply! Original message deleted.`
});
} else {
await lib.discord.channels['@0.1.2'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `Thanks for replying!`,
message_reference: {
message_id: reply.id
}
});
}