Formatting changes

This commit is contained in:
2023-06-14 19:10:34 +02:00
parent b0a31b65dc
commit 703bd8ae26

257
index.js
View File

@@ -1,21 +1,21 @@
const {Client, GatewayIntentBits, Partials, ActivityType, Events, Collection} = require('discord.js'); const { Client, GatewayIntentBits, Partials, ActivityType, Events, Collection } = require('discord.js');
const {botLogChannel, color} = require('./config/options.json'); const { botLogChannel, color } = require('./config/options.json');
const env = require('dotenv').config(); const env = require('dotenv').config();
const token = process.env.TOKEN; const token = process.env.TOKEN;
const mongoURI = process.env.MONGOURI; const mongoURI = process.env.MONGOURI;
const {connect} = require('mongoose'); const { connect } = require('mongoose');
const path = require('path'); const path = require('path');
const fs = require('fs'); const fs = require('fs');
const client = new Client({ const client = new Client({
intents : [ intents: [
GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMembers, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMembers, GatewayIntentBits.MessageContent,
GatewayIntentBits.DirectMessages GatewayIntentBits.DirectMessages
], ],
partials : [ partials: [
Partials.GuildMember, Partials.User, Partials.Message, Partials.Channel Partials.GuildMember, Partials.User, Partials.Message, Partials.Channel
] ]
}); });
client.commands = new Collection(); client.commands = new Collection();
@@ -28,15 +28,14 @@ const cmdFiles = fs.readdirSync(cmdPath).filter(file => file.endsWith('.js'));
for (const file of cmdFiles) { for (const file of cmdFiles) {
const filePath = path.join(cmdPath, file); const filePath = path.join(cmdPath, file);
const cmd = require(filePath); const cmd = require(filePath);
if ('data' in cmd && 'execute' in cmd && cmd.type === 'slash') { if ('data' in cmd && 'execute' in cmd && cmd.type === 'slash') {
client.commands.set(cmd.data.name, cmd); client.commands.set(cmd.data.name, cmd);
} else { } else {
console.log(`[WARNING] The command at ${ console.log(`[WARNING] The command at ${filePath} is missing a required "data", "execute" or "type" property.`);
filePath} is missing a required "data", "execute" or "type" property.`); }
}
} }
//! commands testing //! commands testing
@@ -46,38 +45,37 @@ const cmdTestFiles =
for (const file of cmdTestFiles) { for (const file of cmdTestFiles) {
const filePath = path.join(cmdTestPath, file); const filePath = path.join(cmdTestPath, file);
const cmd = require(filePath); const cmd = require(filePath);
if ('data' in cmd && 'execute' in cmd && cmd.type === 'slash') { if ('data' in cmd && 'execute' in cmd && cmd.type === 'slash') {
client.commands.set(cmd.data.name, cmd); client.commands.set(cmd.data.name, cmd);
} else { } else {
console.log(`[WARNING] The command at ${ console.log(`[WARNING] The command at ${filePath} is missing a required "data", "execute" or "type" property.`);
filePath} is missing a required "data", "execute" or "type" property.`); }
}
} }
//! command handler //! command handler
client.on(Events.InteractionCreate, async interaction => { client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) if (!interaction.isChatInputCommand())
return; return;
const command = interaction.client.commands.get(interaction.commandName); const command = interaction.client.commands.get(interaction.commandName);
if (!command) { if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`); console.error(`No command matching ${interaction.commandName} was found.`);
return; return;
} }
try { try {
await command.execute(interaction); await command.execute(interaction);
} catch (error) { } catch (error) {
console.error(error); console.error(error);
await interaction.reply({ await interaction.reply({
content : 'There was an error while executing this command!', content: 'There was an error while executing this command!',
ephemeral : true ephemeral: true
}) })
} }
}); });
//! commands //! commands
@@ -87,38 +85,37 @@ const contextMenuFiles =
for (const file of contextMenuFiles) { for (const file of contextMenuFiles) {
const filePath = path.join(contextMenuPath, file); const filePath = path.join(contextMenuPath, file);
const cmd = require(filePath); const cmd = require(filePath);
if ('data' in cmd && 'execute' in cmd && cmd.type === 'contextmenu') { if ('data' in cmd && 'execute' in cmd && cmd.type === 'contextmenu') {
client.commands.set(cmd.data.name, cmd); client.commands.set(cmd.data.name, cmd);
} else { } else {
console.log(`[WARNING] The command at ${ console.log(`[WARNING] The command at ${filePath} is missing a required "data", "execute" or "type" property.`);
filePath} is missing a required "data", "execute" or "type" property.`); }
}
} }
//! context menu command handler //! context menu command handler
client.on(Events.InteractionCreate, async interaction => { client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isContextMenuCommand()) if (!interaction.isContextMenuCommand())
return; return;
const command = interaction.client.commands.get(interaction.commandName); const command = interaction.client.commands.get(interaction.commandName);
if (!command) { if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`); console.error(`No command matching ${interaction.commandName} was found.`);
return; return;
} }
try { try {
await command.execute(interaction); await command.execute(interaction);
} catch (error) { } catch (error) {
console.error(error); console.error(error);
await interaction.reply({ await interaction.reply({
content : 'There was an error while executing this command!', content: 'There was an error while executing this command!',
ephemeral : true ephemeral: true
}) })
} }
}); });
//! button events //! button events
@@ -127,38 +124,37 @@ const btnFiles = fs.readdirSync(btnPath).filter(file => file.endsWith('.js'));
for (const file of btnFiles) { for (const file of btnFiles) {
const filePath = path.join(btnPath, file); const filePath = path.join(btnPath, file);
const btn = require(filePath); const btn = require(filePath);
if ('name' in btn && 'execute' in btn && btn.type === 'button') { if ('name' in btn && 'execute' in btn && btn.type === 'button') {
client.events.set(btn.name, btn); client.events.set(btn.name, btn);
} else { } else {
console.log(`[WARNING] The button at ${ console.log(`[WARNING] The button at ${filePath} is missing a required "name", "execute" or "type" property.`);
filePath} is missing a required "name", "execute" or "type" property.`); }
}
} }
//! button event handler //! button event handler
client.on(Events.InteractionCreate, async event => { client.on(Events.InteractionCreate, async event => {
if (!event.isButton()) if (!event.isButton())
return; return;
const event2 = event.client.events.get(event.customId); const event2 = event.client.events.get(event.customId);
if (!event2) { if (!event2) {
console.error(`No event matching ${event.customId} was found.`); console.error(`No event matching ${event.customId} was found.`);
return; return;
} }
try { try {
await event2.execute(event); await event2.execute(event);
} catch (error) { } catch (error) {
console.error(error); console.error(error);
await event.reply({ await event.reply({
content : 'There was an error while executing this event!', content: 'There was an error while executing this event!',
ephemeral : true ephemeral: true
}) })
} }
}) })
//! modals //! modals
@@ -168,60 +164,59 @@ const modalFiles =
for (const file of modalFiles) { for (const file of modalFiles) {
const filePath = path.join(modalPath, file); const filePath = path.join(modalPath, file);
const modal = require(filePath); const modal = require(filePath);
if ('name' in modal && 'execute' in modal && modal.type === 'modal') { if ('name' in modal && 'execute' in modal && modal.type === 'modal') {
client.on(Events.InteractionCreate, modal.execute); client.on(Events.InteractionCreate, modal.execute);
} else { } else {
console.log(`[WARNING] The modal at ${ console.log(`[WARNING] The modal at ${filePath} is missing a required "name", "execute" or "type" property.`);
filePath} is missing a required "name", "execute" or "type" property.`); }
}
} }
client.on(Events.InteractionCreate, async interaction => { client.on(Events.InteractionCreate, async interaction => {
if (interaction.isCommand()) { if (interaction.isCommand()) {
console.log(interaction.user.username + "#" + console.log(interaction.user.username + "#" +
interaction.user.discriminator + " ran " + interaction.user.discriminator + " ran " +
interaction.commandName); interaction.commandName);
} else if (interaction.isButton()) { } else if (interaction.isButton()) {
console.log(interaction.user.username + "#" + console.log(interaction.user.username + "#" +
interaction.user.discriminator + " clicked " + interaction.user.discriminator + " clicked " +
interaction.customId); interaction.customId);
} }
}); });
client.on(Events.ClientReady, () => { client.on(Events.ClientReady, () => {
console.log("Logged in as " + client.user.tag + "!"); console.log("Logged in as " + client.user.tag + "!");
const channel = client.channels.cache.get(botLogChannel); const channel = client.channels.cache.get(botLogChannel);
const embedColor = Number(color.replace('#', '0x')) const embedColor = Number(color.replace('#', '0x'))
if (!channel) { if (!channel) {
return; return;
} }
channel.send( channel.send(
{embeds : [ {description : `Bot is online!`, color : embedColor} ]}); { embeds: [{ description: `Bot is online!`, color: embedColor }] });
}); });
client.on(Events.ClientReady, () => { client.on(Events.ClientReady, () => {
client.user.setActivity( client.user.setActivity(
{name : "over the Illegitimate Server", type : ActivityType.Watching}); { name: "over the Illegitimate Server", type: ActivityType.Watching });
const activities = [ const activities = [
{name : "with Jone the idiot", type : ActivityType.Playing}, { name: "with Jone the idiot", type: ActivityType.Playing },
{name : "with Martina the bot", type : ActivityType.Playing}, { name: "with Martina the bot", type: ActivityType.Playing },
{name : "urCryhard steal finals again", type : ActivityType.Watching}, { name: "urCryhard steal finals again", type: ActivityType.Watching },
{name : "with Perlcence the AI", type : ActivityType.Playing}, { name: "with Perlcence the AI", type: ActivityType.Playing },
{name : "my creator Taken", type : ActivityType.Watching}, { name: "my creator Taken", type: ActivityType.Watching },
{name : "with ur mom in my bed", type : ActivityType.Playing}, { name: "with ur mom in my bed", type: ActivityType.Playing },
{name : "over the Illegitimate Server", type : ActivityType.Watching} { name: "over the Illegitimate Server", type: ActivityType.Watching }
]; ];
let i = 0; let i = 0;
setInterval(() => setInterval(() =>
client.user.setActivity(activities[i++ % activities.length]), client.user.setActivity(activities[i++ % activities.length]),
1000 * 60 * 30) 1000 * 60 * 30)
}); });
client.on(Events.ClientReady, () => { client.user.setStatus('dnd'); }); client.on(Events.ClientReady, () => { client.user.setStatus('dnd'); });
client.login(token); client.login(token);