Whitelist role(s) that can post messages in channels. If a user does not have the role their messages will be deleted and the user will recieve a DM from the bot with further instructions for getting verified. If a user without the whitelisted role(s) tries to spam the designated channel(s) the bot will assign them a muted role. Credit: JacobLee
// authenticates you with the API standard library
// type `await lib.` to display API autocomplete
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
if (
process.env.SUPPORT_CHANNEL_IDS.split(',').includes(
context.params.event.channel_id
)
) {
let guildInfo = await lib.discord.guilds['@0.2.4'].retrieve({
guild_id: `${context.params.event.guild_id}`,
});
let whitelistRoles = process.env.WHITELIST_ROLES.split(',');
let canPost = !!whitelistRoles.filter((role) => {
return context.params.event.member.roles.includes(role);
}).length;
if (!canPost && guildInfo.owner_id !== context.params.event.author.id) {
try {
await lib.discord.channels['@0.3.1'].messages.destroy({
message_id: `${context.params.event.id}`,
channel_id: `${context.params.event.channel_id}`,
});
} catch (e) {
console.log(e);
if (e.message.toLowerCase().includes('rate limited')) {
await lib.discord.guilds['@0.2.4'].members.roles.update({
role_id: process.env.MUTE_ROLEID,
user_id: `${context.params.event.author.id}`,
guild_id: `${context.params.event.guild_id}`,
});
}
}
try {
let message = [
`Hey <@${context.params.event.author.id}> π, sorry you can't post in this channel until you've been verified.`,
];
if (!!context.params.event.content) {
message.push(
[
`Here's the message we removed so you can repost it once you're verified:`,
'`===================================`',
`${context.params.event.content}`,
'`===================================`',
].join('\n')
);
}
await lib.discord.users['@0.2.1'].dms.create({
recipient_id: `${context.params.event.author.id}`,
content: message.join('\n'),
embeds: [
{
type: 'rich',
title: `How to get β
Verified`,
description: '',
},
{
type: 'rich',
title: `π Step 1:`,
description: [`-`, `-`, `-`].join('\n'),
color: 0x5865f2,
},
{
type: 'rich',
title: `πΎ Step 2:`,
description: [`-`, `-`, `-`].join('\n'),
color: 0x57f287,
},
],
});
} catch (e) {
console.log('Could not send DM: ', e.message);
}
let messageDelay = await lib.utils.kv['@0.1.16'].get({
key: `support_mod__${context.params.event.author.id}`,
defaultValue: false,
});
if (messageDelay) {
return;
}
await lib.utils.kv['@0.1.16'].set({
key: `support_mod__${context.params.event.author.id}`,
value: true,
ttl: 60 * 60 * 24,
});
await lib.discord.channels['@0.3.1'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `Hey <@${context.params.event.author.id}>. In order to ask questions here, you must first get verified`,
});
}
}