This snippet allows members with the BAN_MEMBERS permission to Ban other members from the server. When used, this command will ban the member and return his ID for future use. This command will also send the banned member a DM with the server from which they were banned from, why they were banned, and who banned them, all in a fancy embed. IF YOU NEED HELP SETTING UP, you can ping @Zeno in the Autocode Discord for support. Hope you enjoy!
// authenticates you with the API standard library
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
let isBAN_MEMBERS =
(context.params.event.member.permissions & (1 << 2)) === 1 << 2;
if (isBAN_MEMBERS) {
let userId = context.params.event.data.options[0].value;
let reason = context.params.event.data.options[1].value;
let guild = await lib.discord.guilds['@0.1.0'].retrieve({
guild_id: context.params.event.guild_id, // required
});
await lib.discord.users['@0.1.4'].dms.create({
recipient_id: `${userId}`,
content: '',
embed: {
type: 'rich',
title: `**You were banned!**`,
description: `
*From:* **${guild.name}**
*For:* **${reason}**
*Moderator:* **<@${context.params.event.member.user.id}>**`,
color: 131644,
},
});
let result = await lib.discord.guilds['@0.1.0'].bans.create({
user_id: `${userId}`,
guild_id: `${context.params.event.guild_id}`,
reason: `${reason}`,
});
await lib.discord.channels['@0.1.1'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `**<@${context.params.event.member.user.id}> - has banned <@${userId}> - ID: ${userId}**`,
});
} else {
await lib.discord.channels['@0.2.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `**<@${context.params.event.member.user.id}> - You need the BAN_MEMBERS permission to use the Ban command**`,
});
}