This snippet sends a report to the channel you set as the environment variable `USER_REPORTS_CHANNEL_ID` and sends a DM to the user who reported, confirming that their report has been sent. And a logs the event in a channel you set as the environment variable `CMDLOGS_CHANNEL_ID`. Remember to register a slash command named "/report" with two required options, "User", "String" with the name "user" and "reason" via the [command builder](https://autocode.com/tools/discord/command-builder/). (This command idea was inspired by the /report command in [Autocode Developers](https://discord.gg/autocode) Discord)
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
let event = context.params.event;
let reportedUser = event.data.options[0].value;
let reason = event.data.options[1].value;
await lib.discord.channels['@0.2.0'].messages.create({
channel_id: process.env.USER_REPORTS_CHANNEL_ID,
content: `User Report`,
tts: false,
embeds: [
{
type: 'rich',
title: '',
description: '',
color: 0xd34f4f,
fields: [
{
name: `Author`,
value: `<@${event.member.user.id}>`,
},
{
name: `User`,
value: `<@${reportedUser}>`,
},
{
name: `Reason`,
value: `${reason}`,
},
],
},
],
});
await lib.discord.users['@0.1.5'].dms.create({
recipient_id: event.member.user.id,
content: ``,
tts: false,
embeds: [
{
type: 'rich',
title: `Hey ${event.member.user.username}, your report has been sent!`,
description: `\`\`\`\n${reason}\n\`\`\``,
color: 0x5865f2,
},
],
});
// Command Logs
await lib.discord.channels['@0.2.0'].messages.create({
channel_id: process.env.CMDLOGS_CHANNEL_ID,
content: `Command Usage`,
tts: false,
embeds: [
{
type: 'rich',
title: '',
description: '',
color: 0x0dedcf,
fields: [
{
name: `Author`,
value: `<@${event.member.user.id}>`,
},
{
name: `Channel`,
value: `<#${event.channel_id}>`,
},
{
name: `Command`,
value: `/report`,
},
],
},
],
});