This snippet replies politely and privately to a user running an unauthorized command, but also reports an unauthorized user to a mod logs channel.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const adminRole = `0`; // The ID of the specified role allowed to run this command.
const loggingchannel = `0`; // The ID of the channel where you want your bot to report the user.
if (context.params.event.member.roles.includes(adminRole)) {
// Run some code.
} else {
// Send a private response to the user to inform them they are not allowed to use this command. Alternatively, you can comment out this section to prevent a response to the user.
await lib.discord.interactions['@1.0.1'].responses.ephemeral.create({
token: `${context.params.event.token}`,
channel_id: `${context.params.event.channel_id}`,
content: `You are not authorized to use this command.`,
});
// Reports the user to diagnose a potential DDoS or other unwanted behavior.
await lib.discord.channels['@0.3.2'].messages.create({
channel_id: `${loggingchannel}`,
content: `Unauthorized User <@${context.params.event.member.user.id}> attempted to use the /${context.params.event.data.name} command.`,
});
}