Slash command (/event) that generates an embed representing an event. Members of your server can RSVP via reaction. Requires you to set up a slash command with required options for title, date, and time, and optional options for limit and description.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const cpe = context.params.event;
const backtick = '`';
let title = cpe.data.options[0].value;
let date = cpe.data.options[1].value;
let time = cpe.data.options[2].value;
let limit = 0;
let description = '';
try {limit = cpe.data.options[3].value;}
catch (e) {limit = 0;}
try {description = cpe.data.options[4].value;}
catch (e) {description = '';}
let user = await lib.discord.users['@0.1.4'].retrieve({
user_id: cpe.member.user.id,
});
function field()
{
let output = [];
output[0] =
{
name: 'Time:',
value: `${backtick}${date} at ${time}${backtick}`,
};
if (limit != 0) {
output[1] = {name: 'Limit:', value: limit};
}
if (description != '') {
output[2] = {name: 'Description:', value: `${description}`};
}
return output;
}
let event = await lib.discord.channels['@0.1.2'].messages.create({
channel_id: cpe.channel_id,
content: ` `,
embed:
{
title: `${title}`,
color: 0x33669a,
author: {
name: cpe.member.user.username,
icon_url: user.avatar_url,
},
fields: field(),
},
});
await lib.discord.channels['@0.1.2'].messages.reactions.create({
emoji: `👍`,
message_id: event.id,
channel_id: event.channel_id,
});
await lib.discord.channels['@0.1.2'].messages.reactions.create({
emoji: `👎`,
message_id: event.id,
channel_id: event.channel_id,
});