mirror of
https://github.com/aydenjahola/discord-multipurpose-bot.git
synced 2024-11-22 00:35:56 +00:00
67 lines
2 KiB
JavaScript
67 lines
2 KiB
JavaScript
require("dotenv").config();
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
const { Client, GatewayIntentBits, Collection } = require("discord.js");
|
|
const mongoose = require("mongoose");
|
|
|
|
const client = new Client({
|
|
intents: [
|
|
GatewayIntentBits.Guilds,
|
|
GatewayIntentBits.GuildMessages,
|
|
GatewayIntentBits.MessageContent,
|
|
],
|
|
});
|
|
|
|
client.commands = new Collection();
|
|
|
|
// Load command files dynamically
|
|
const commandsPath = path.join(__dirname, "commands");
|
|
const commandFiles = fs
|
|
.readdirSync(commandsPath)
|
|
.filter((file) => file.endsWith(".js"));
|
|
|
|
for (const file of commandFiles) {
|
|
const filePath = path.join(commandsPath, file);
|
|
const command = require(filePath);
|
|
client.commands.set(command.data.name, command);
|
|
}
|
|
|
|
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
|
|
client.user.setActivity({ type: "WATCHING", name: "Degenerate Gamers" });
|
|
|
|
// 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));
|
|
});
|
|
|
|
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);
|
|
} catch (error) {
|
|
console.error(error);
|
|
await interaction.reply({
|
|
content: "There was an error while executing this command!",
|
|
ephemeral: true,
|
|
});
|
|
}
|
|
});
|
|
|
|
client.login(process.env.BOT_TOKEN);
|