Users can use /report [message] to send staff a message to a specified channel (can be staff only channel). Only users with certain roles (that you specify) can use the command, the role mentioned in the Report channel can also be changed. You must set up the slash command in the builder with an Option of String: https://autocode.com/tools/discord/command-builder/
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
// START OF CUSTOMISABLE!
let reportChannel = `CHANNEL_ID_HERE`; //what channel the reports are sent in for Admins to read
let mentionedRole = `ROLE_ID_HERE`; //role mentioned in reports channel before displaying the report (used to ping Admins when a report is created)
let requiredRole = [//used to allow only certain roles to use the report command
`ROLE_ID_HERE`, // role name here to keep track e.g: member
`ROLE_ID_HERE`, // role name here to keep track e.g: vip
`ROLE_ID_HERE`, // role name here to keep track e.g: mod
`ROLE_ID_HERE`, // role name here to keep track e.g: admin
];
// END OF CUSTOMISABLE!
let messageString = context.params.event.data.options[0].value; //takes the first option and calls it messageString
let authorString = context.params.event.member.user.id; //calls the comand user authorString
let authorStringInfo = await lib.discord.guilds['@0.1.0'].members.retrieve({ //get info about
user_id: `${authorString}`, //this user
guild_id: `${context.params.event.guild_id}`, //in this guild
});
let hasRequiredRole = authorStringInfo.roles.find((roleId) => { //make hasRequiredRole tru if the user has roles
return requiredRole.includes(roleId); // which include atleast one of the requiredRole
});
if (hasRequiredRole) {
await lib.discord.channels['@0.1.0'].messages.create({ //create a message
channel_id: `${reportChannel}`, //in this channel
content: `<@&${mentionedRole}> -> <@${authorString}> **Reports:** ${messageString}`, //saying this
});
await lib.discord.channels['@0.1.1'].messages.create({ //create another message
channel_id: `${context.params.event.channel_id}`, //in the channel the command was sent in
content: `**REPORTED!**`, //the response
});
} if (!hasRequiredRole) { //if hasRequiredRole wasnt triggered
await lib.discord.channels['@0.2.0'].messages.create({ //create message
channel_id: `${context.params.event.channel_id}`, //in this channel
content: `You do not have access to this command!`, //saying this
});
}
//.MeltedButter#9266