This little code snippet is meant to be an example/starting point for people looking to use the bot_mention discord endpoint. The bot will reply to your message with the amount of times you've pinged them.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
let user_id = context.params.event.author.id;
let channel_id = context.params.event.channel_id;
let message_id = context.params.event.id;
let mentions = await lib.keyvalue.store['@0.1.16'].get({
key: `${user_id}-bot-mentions`,
defaultValue: '0',
});
let number = parseInt(mentions, 10);
if (mentions == '0') {
await lib.discord.channels['@0.3.2'].messages.create({
channel_id: channel_id,
content: `This is the first time you've mentioned me!`,
message_reference: {
message_id: message_id,
},
});
await lib.keyvalue.store['@0.1.16'].set({
key: `${user_id}-bot-mentions`,
value: number + 2,
});
console.log(mentions);
} else {
await lib.discord.channels['@0.3.2'].messages.create({
channel_id: channel_id,
content: `You have mentioned me ${mentions} times!`,
message_reference: {
message_id: message_id,
},
});
await lib.keyvalue.store['@0.1.16'].set({
key: `${user_id}-bot-mentions`,
value: number + 1,
});
}