Created
May 27, 2022 22:10
-
-
Save PhantomNimbi/c0adb76938f543922d9101f34efe52b5 to your computer and use it in GitHub Desktop.
Pylon.bot Ban System
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as CONFIG from '../modules/config'; | |
import * as CMD from '../modules/config/commands'; | |
const GROUP = CONFIG.CLIENT.COMMANDS; | |
const CHANNELS = CONFIG.CHANNELS; | |
const EMBEDS = CONFIG.EMBEDS; | |
const IMAGES = CONFIG.IMAGES; | |
GROUP.subcommand( | |
{ | |
name: CMD.BAN_COMMAND.NAME, | |
description: CMD.BAN_COMMAND.DESCRIPTION, | |
filters: CMD.BAN_COMMAND.PERMISSIONS, | |
}, | |
(subCommand) => { | |
subCommand.on( | |
{ | |
name: CMD.BAN_COMMAND.SUBCOMMAND.ADD.NAME, | |
description: CMD.BAN_COMMAND.SUBCOMMAND.ADD.DESCRIPTION, | |
aliases: CMD.BAN_COMMAND.SUBCOMMAND.ADD.ALIASES, | |
filters: CMD.BAN_COMMAND.SUBCOMMAND.ADD.PERMISSIONS, | |
}, | |
(args) => ({ | |
user: args.user(), | |
reason: args.textOptional(), | |
}), | |
async (message, { user, reason }) => { | |
try { | |
const guild = await discord.getGuild(); | |
const logging_channel = await discord.getGuildTextChannel( | |
CHANNELS.LOGGING_CHANNEL | |
); | |
await guild.createBan(user, { | |
deleteMessageDays: 7, | |
reason: reason || undefined, | |
}); | |
const embed = new discord.Embed(); | |
embed.setTitle(EMBEDS.BAN_HEADER_TEXT.ADD); | |
embed.setThumbnail({ url: user.getAvatarUrl(discord.ImageType.PNG) }); | |
embed.addField({ | |
name: 'User Name', | |
value: `${user.username}`, | |
inline: true, | |
}); | |
embed.addField({ | |
name: 'User ID', | |
value: `${user.id}`, | |
inline: true, | |
}); | |
embed.addField({ | |
name: 'Reason', | |
value: '```\n' + reason + '\n```', | |
inline: false, | |
}); | |
embed.setTimestamp(new Date().toISOString()); | |
embed.setColor(EMBEDS.DEFAULT_COLOR.DARK_RED); | |
embed.setFooter({ | |
text: EMBEDS.FOOTER_TEXT, | |
iconUrl: IMAGES.PYLON_LOGO, | |
}); | |
if (guild && logging_channel) { | |
await message.addReaction('✅'); | |
logging_channel?.sendMessage({ | |
content: '', | |
embed: embed, | |
}); | |
} | |
} catch (e) { | |
const channel = await discord.getTextChannel(CHANNELS.ERROR_CHANNEL); | |
if (!channel) throw new Error(':x: Invalid Error Channel Specified!'); | |
const embed = new discord.Embed(); | |
embed.setDescription( | |
'```ts\n[' + e.name + '(' + e.code + '): ' + e.message + ']\n```' | |
); | |
embed.addField({ | |
name: 'Error Stack', | |
value: '```ts\n' + e.stack + '\n```', | |
inline: false, | |
}); | |
embed.addField({ | |
name: 'Error Code', | |
value: '```\n' + String(e.code) + '\n```', | |
inline: true, | |
}); | |
embed.addField({ | |
name: 'Channel ID', | |
value: '```\n' + String(message.channelId) + '\n```', | |
inline: true, | |
}); | |
embed.setThumbnail({ url: IMAGES.PYLON_LOGO }); | |
embed.setColor(EMBEDS.DEFAULT_COLOR.ORANGE); | |
embed.setTimestamp(new Date().toISOString()); | |
embed.setFooter({ | |
text: EMBEDS.FOOTER_TEXT, | |
iconUrl: IMAGES.PYLON_LOGO, | |
}); | |
console.error(e); | |
channel?.sendMessage({ embed: embed }); | |
} | |
} | |
); | |
subCommand.on( | |
{ | |
name: CMD.BAN_COMMAND.SUBCOMMAND.LIST.NAME, | |
description: CMD.BAN_COMMAND.SUBCOMMAND.LIST.DESCRIPTION, | |
aliases: CMD.BAN_COMMAND.SUBCOMMAND.LIST.ALIASES, | |
filters: CMD.BAN_COMMAND.SUBCOMMAND.LIST.PERMISSIONS, | |
}, | |
(args) => ({ | |
user: args.user(), | |
reason: args.textOptional(), | |
}), | |
async (message, { user, reason }) => { | |
try { | |
await message.delete(); | |
const guild = await message.getGuild(); | |
const banlist = await guild.getBans(); | |
var i; | |
var text = ''; | |
for (i = 0; i < banlist.length; i++) { | |
text += | |
`${banlist[i].user.toMention()} (ID: ${ | |
banlist[i].user.id | |
})\n**BAN REASON**\n${banlist[i].reason}` + `\n\n`; | |
} | |
const embed = new discord.Embed(); | |
embed.setTitle(EMBEDS.BAN_HEADER_TEXT.LIST); | |
embed.setDescription(text); | |
embed.setThumbnail({ | |
url: `${guild.getIconUrl(discord.ImageType.PNG)}`, | |
}); | |
embed.setColor(EMBEDS.DEFAULT_COLOR.DARK_RED); | |
embed.setFooter({ | |
text: EMBEDS.FOOTER_TEXT, | |
iconUrl: IMAGES.PYLON_LOGO, | |
}); | |
embed.setTimestamp(new Date().toISOString()); | |
if (guild) { | |
message.addReaction('✅'); | |
await message.reply({ | |
content: '', | |
embed: embed, | |
}); | |
} | |
} catch (e) { | |
const channel = await discord.getTextChannel(CHANNELS.ERROR_CHANNEL); | |
if (!channel) throw new Error(':x: Invalid Error Channel Specified!'); | |
const embed = new discord.Embed(); | |
embed.setDescription( | |
'```ts\n[' + e.name + '(' + e.code + '): ' + e.message + ']\n```' | |
); | |
embed.addField({ | |
name: 'Error Stack', | |
value: '```ts\n' + e.stack + '\n```', | |
inline: false, | |
}); | |
embed.addField({ | |
name: 'Error Code', | |
value: '```\n' + String(e.code) + '\n```', | |
inline: true, | |
}); | |
embed.addField({ | |
name: 'Channel ID', | |
value: '```\n' + String(message.channelId) + '\n```', | |
inline: true, | |
}); | |
embed.setThumbnail({ url: IMAGES.PYLON_LOGO }); | |
embed.setColor(EMBEDS.DEFAULT_COLOR.ORANGE); | |
embed.setTimestamp(new Date().toISOString()); | |
embed.setFooter({ | |
text: EMBEDS.FOOTER_TEXT, | |
iconUrl: IMAGES.PYLON_LOGO, | |
}); | |
console.error(e); | |
channel?.sendMessage({ embed: embed }); | |
} | |
} | |
); | |
subCommand.on( | |
{ | |
name: CMD.BAN_COMMAND.SUBCOMMAND.REMOVE.NAME, | |
description: CMD.BAN_COMMAND.SUBCOMMAND.REMOVE.DESCRIPTION, | |
filters: CMD.BAN_COMMAND.SUBCOMMAND.REMOVE.PERMISSIONS, | |
}, | |
(args) => ({ | |
user: args.user(), | |
reason: args.textOptional(), | |
}), | |
async (message, { user, reason }) => { | |
try { | |
const guild = await discord.getGuild(); | |
const logging_channel = await discord.getGuildTextChannel( | |
CHANNELS.LOGGING_CHANNEL | |
); | |
await guild.createBan(user, { | |
deleteMessageDays: 7, | |
reason: reason || undefined, | |
}); | |
const embed = new discord.Embed(); | |
embed.setTitle(EMBEDS.BAN_HEADER_TEXT.REMOVE); | |
embed.setThumbnail({ url: user.getAvatarUrl(discord.ImageType.PNG) }); | |
embed.addField({ | |
name: 'User Name', | |
value: `${user.username}`, | |
inline: true, | |
}); | |
embed.addField({ | |
name: 'User ID', | |
value: `${user.id}`, | |
inline: true, | |
}); | |
embed.addField({ | |
name: 'Reason', | |
value: '```\n' + reason + '\n```', | |
inline: false, | |
}); | |
embed.setTimestamp(new Date().toISOString()); | |
embed.setColor(EMBEDS.DEFAULT_COLOR.DARK_RED); | |
embed.setFooter({ | |
text: EMBEDS.FOOTER_TEXT, | |
iconUrl: IMAGES.PYLON_LOGO, | |
}); | |
if (guild && logging_channel) { | |
await message.addReaction('✅'); | |
logging_channel?.sendMessage({ | |
content: '', | |
embed: embed, | |
}); | |
} | |
} catch (e) { | |
const channel = await discord.getTextChannel(CHANNELS.ERROR_CHANNEL); | |
if (!channel) throw new Error(':x: Invalid Error Channel Specified!'); | |
const embed = new discord.Embed(); | |
embed.setDescription( | |
'```ts\n[' + e.name + '(' + e.code + '): ' + e.message + ']\n```' | |
); | |
embed.addField({ | |
name: 'Error Stack', | |
value: '```ts\n' + e.stack + '\n```', | |
inline: false, | |
}); | |
embed.addField({ | |
name: 'Error Code', | |
value: '```\n' + String(e.code) + '\n```', | |
inline: true, | |
}); | |
embed.addField({ | |
name: 'Channel ID', | |
value: '```\n' + String(message.channelId) + '\n```', | |
inline: true, | |
}); | |
embed.setThumbnail({ url: IMAGES.PYLON_LOGO }); | |
embed.setColor(EMBEDS.DEFAULT_COLOR.ORANGE); | |
embed.setTimestamp(new Date().toISOString()); | |
embed.setFooter({ | |
text: EMBEDS.FOOTER_TEXT, | |
iconUrl: IMAGES.PYLON_LOGO, | |
}); | |
console.error(e); | |
channel?.sendMessage({ embed: embed }); | |
} | |
} | |
); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment