2024-09-02 18:32:03 +01:00
|
|
|
require("dotenv").config();
|
|
|
|
const fs = require("fs");
|
|
|
|
const path = require("path");
|
2024-09-02 18:51:45 +01:00
|
|
|
const { Client, GatewayIntentBits, Collection } = require("discord.js");
|
|
|
|
const mongoose = require("mongoose");
|
2024-09-02 18:32:03 +01:00
|
|
|
|
|
|
|
const client = new Client({
|
|
|
|
intents: [
|
|
|
|
GatewayIntentBits.Guilds,
|
|
|
|
GatewayIntentBits.GuildMessages,
|
|
|
|
GatewayIntentBits.MessageContent,
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
client.commands = new Collection();
|
|
|
|
|
2024-09-02 18:51:45 +01:00
|
|
|
// Load command files dynamically
|
|
|
|
const commandsPath = path.join(__dirname, "commands");
|
2024-09-02 18:32:03 +01:00
|
|
|
const commandFiles = fs
|
2024-09-02 18:51:45 +01:00
|
|
|
.readdirSync(commandsPath)
|
2024-09-02 18:32:03 +01:00
|
|
|
.filter((file) => file.endsWith(".js"));
|
|
|
|
|
|
|
|
for (const file of commandFiles) {
|
2024-09-02 18:51:45 +01:00
|
|
|
const filePath = path.join(commandsPath, file);
|
|
|
|
const command = require(filePath);
|
2024-09-02 18:32:03 +01:00
|
|
|
client.commands.set(command.data.name, command);
|
|
|
|
}
|
|
|
|
|
2024-09-02 18:51:45 +01:00
|
|
|
client.once("ready", () => {
|
|
|
|
console.log(`\n==============================`);
|
|
|
|
console.log(`🤖 Logged in as ${client.user.tag}`);
|
|
|
|
console.log(`==============================`);
|
|
|
|
console.log(`📋 Registered Commands:\n`);
|
|
|
|
client.commands.forEach((command) => {
|
|
|
|
console.log(`🔹 /${command.data.name} - ${command.data.description}`);
|
|
|
|
});
|
|
|
|
console.log(`\n==============================\n`);
|
|
|
|
|
|
|
|
// Set the bot's activity here
|
2024-09-02 18:57:41 +01:00
|
|
|
client.user.setActivity({ type: "WATCHING", name: "Degenerate Gamers" });
|
2024-09-02 18:51:45 +01:00
|
|
|
|
|
|
|
// Database connection (MongoDB)
|
|
|
|
mongoose
|
|
|
|
.connect(process.env.MONGODB_URI)
|
|
|
|
.then(() => console.log("✅ Connected to MongoDB"))
|
|
|
|
.catch((err) => console.error("❌ Failed to connect to MongoDB", err));
|
2024-09-02 18:32:03 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
client.on("interactionCreate", async (interaction) => {
|
|
|
|
if (!interaction.isCommand()) return;
|
|
|
|
|
|
|
|
const command = client.commands.get(interaction.commandName);
|
|
|
|
|
|
|
|
if (!command) return;
|
|
|
|
|
|
|
|
try {
|
|
|
|
await command.execute(interaction, client);
|
2024-09-02 18:51:45 +01:00
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
2024-09-02 18:32:03 +01:00
|
|
|
await interaction.reply({
|
|
|
|
content: "There was an error while executing this command!",
|
|
|
|
ephemeral: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
client.login(process.env.BOT_TOKEN);
|