This snippet will help your bot differentiate whether it's a reply ping to the bot's message or just a usual bot mention through message so that it doesn't reply randomly without knowing what type of ping it is receiving.
// authenticates you with the API standard library
// type `await lib.` to display API autocomplete
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
//just to quickly check for user's avatar for displaying in the help embed's footer
let avatar = context.params.event.author.avatar ? `https://cdn.discordapp.com/avatars/${context.params.event.author.id}/${context.params.event.author.avatar}.png` : `https://discordapp.com/assets/322c936a8c8be1b803cd94861bdfa868.png`;
//First, we check if the mention is a reply with ping or a usual message ping.
//start by checking to see if a reply exists
if (context.params.event.referenced_message !== null) {
//this could be a reply with ping message. Double confirm to see if the message contains a ping by retrieving the message.
let message = await lib.discord.channels['@0.3.0'].messages.retrieve({
message_id: `${context.params.event.id}`,
channel_id: `${context.params.event.channel_id}`,
});
console.log(message.referenced_message); //this returns the object for the message your user referenced
console.log(context.params.event.content); //this logs the content of the message (easier for you to know but unnecessary to keep)
console.log(`This is a reply ping! You can choose to ignore reply pings and only answer to bot mentions that are through messages.`);
//for your better understanding, let's send a bot message to let you know how this works
await lib.discord.channels['@0.3.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `That's a reply to my message **WITH A PING**!`
});
} else {
//If reply does not exist, this is definitely a message ping.
console.log(context.params.event.content); //this logs the content of the message (easier for you to know but unnecessary to keep)
console.log(`This is a message ping! Your bot mention function can be used here so that it doesn't answer to reply pings.`);
//for your better understanding, let's send a bot message to let you know how this works
await lib.discord.channels['@0.3.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `That's a bot mention through a message! You can show your bot prefix when a user mentioned your bot! Here's an example embed:)`,
"embeds": [
{
"type": "rich",
"title": `❓ Need some help?`,
"description": `Hey there! You pinged me! Just a reminder, my bot is \`n!\`\n\nYou can type \`n!help\` for help with the list of avalable commands!\n\nI reply when you say \`Hi\`, \`Hey\`, \`Sup\` and \`Cya\`! You can try that out if you want to see how I response!`,
"color": 0x00FFFF,
"footer": {
"text": `Requested by ${context.params.event.author.username}`,
"icon_url": `${avatar}`
}
}
]
});
}
//hope you learn something:)