A Discord Slash command that sends the current bot latency to the channel where the command was used by a user who has the ADMIN_ROLE. If a user who used the command but does not have the ADMIN_ROLE will get a DM sent from the bot saying "Hey (username)! You don't have the permission to use the command /ping." Remember to register a slash command named "/ping" via https://autocode.com/tools/discord/command-builder/. (Credits to @jacoblee's "Discord Ping Latency Command" snippet) (Thanks to @meiraba for helping with this command)
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
let adminRole = process.env.ADMIN_ROLE;
let event = context.params.event;
if (event.member.roles.includes(adminRole)) {
let latency = new Date() - new Date(context.params.event.received_at);
await lib.discord.channels['@0.2.0'].messages.create({
channel_id: event.channel_id,
content: `Pong! ${latency}ms`,
});
} else {
await lib.discord.users['@0.1.5'].dms.create({
recipient_id: event.member.user.id,
content: `Hey ${event.member.user.username}! You don't have the permission to use the command \`/ping\`.`,
});
}