If you mention the bot with a trigger word it will reply with a random phrase
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
// Helper functions
// Normalizes user input to better identify keyword
function sanitizeSaid(msg) {
return msg.replace(/[^\w\s]|_/g, '').toLowerCase();
}
// Generates random number in range
function randomNumber(min, max) {
return Math.floor(Math.random() * (max - min) + min);
}
// Set the variable we will use for user input
let saidToBot = sanitizeSaid(context.params.event.content);
// The word the bot will look for in people's message, you can change this to whatever single word you like
let triggerWord = 'quote';
// Put your own quotes or phrases here. If you use a the ' character inside the quote, make sure to escape it like this: I\'ll
let botQuotes = [
'“Be yourself; everyone else is already taken.” ― Oscar Wilde',
'“So many books, so little time.” ― Frank Zappa',
'“You know you\'re in love when you can\'t fall asleep because reality is finally better than your dreams.” ― Dr. Seuss',
'“You only live once, but if you do it right, once is enough.” ― Mae West',
'“If you tell the truth, you don\'t have to remember anything.” ― Mark Twain',
'“The fool doth think he is wise, but the wise man knows himself to be a fool.” ― William Shakespeare, As You Like It',
];
// Check if the user says the trigger word in the mention
if (saidToBot.split(' ').includes(triggerWord)) {
// Simulate typing
await lib.discord.channels['@0.3.0'].typing.create({
channel_id: context.params.event.channel_id, // required
});
// Have bot say one of the quotes in the channel
await lib.discord.channels['@0.2.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: botQuotes[Math.floor(Math.random() * botQuotes.length)],
tts: false,
embeds: [],
});
}