Creates an `!info <key>` command that sends a message with a custom embed for that key if it exists. Try `!info jim` or `!info bob` to see the embeds in action.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const event = context.params.event;
// Default commands work with 'jim' and 'bob' i.e. !info jim / !info bob
const command = '!info';
const embeds = {
jim: {
title: 'Jim',
description: 'Savour of the universe',
},
bob: {
title: 'Bob',
description: 'The worlds best painter',
fields: [
{name: 'First Name', value: 'Bob'},
{name: 'Occupation', value: 'Painter'},
],
},
};
// Is this our command?
if (!event.content.startsWith(command)) return;
// Do we have a name?
const name = event.content.replace(command, '').trim();
const embed = embeds[name];
if (!name)
return lib.discord.channels['@0.2.0'].messages.create({
channel_id: event.channel_id,
content: `Please provide a name`,
});
if (!embed)
return lib.discord.channels['@0.2.0'].messages.create({
channel_id: event.channel_id,
content: `No embed exists for '${name}'`,
});
return lib.discord.channels['@0.2.0'].messages.create({
channel_id: event.channel_id,
content: `Info for ${name}`,
embed: embeds[name],
});