2024-09-02 18:32:03 +01:00
|
|
|
require("dotenv").config();
|
2024-09-02 19:12:59 +01:00
|
|
|
const {
|
|
|
|
Client,
|
|
|
|
GatewayIntentBits,
|
|
|
|
Collection,
|
|
|
|
REST,
|
|
|
|
Routes,
|
|
|
|
} = require("discord.js");
|
|
|
|
const mongoose = require("mongoose");
|
2024-09-02 18:32:03 +01:00
|
|
|
const fs = require("fs");
|
|
|
|
const path = require("path");
|
|
|
|
|
|
|
|
const client = new Client({
|
|
|
|
intents: [
|
|
|
|
GatewayIntentBits.Guilds,
|
|
|
|
GatewayIntentBits.GuildMessages,
|
|
|
|
GatewayIntentBits.MessageContent,
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
2024-09-02 19:12:59 +01:00
|
|
|
const GUIlD_ID = process.env.GUILD_ID;
|
|
|
|
|
2024-09-02 18:32:03 +01:00
|
|
|
client.commands = new Collection();
|
|
|
|
|
|
|
|
const commandFiles = fs
|
2024-09-02 19:12:59 +01:00
|
|
|
.readdirSync(path.join(__dirname, "commands"))
|
2024-09-02 18:32:03 +01:00
|
|
|
.filter((file) => file.endsWith(".js"));
|
|
|
|
|
|
|
|
for (const file of commandFiles) {
|
2024-09-02 19:12:59 +01:00
|
|
|
const command = require(`./commands/${file}`);
|
2024-09-02 18:32:03 +01:00
|
|
|
client.commands.set(command.data.name, command);
|
|
|
|
}
|
|
|
|
|
2024-09-02 19:12:59 +01:00
|
|
|
client.once("ready", async () => {
|
2024-09-02 18:51:45 +01:00
|
|
|
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`);
|
|
|
|
|
2024-09-02 19:12:59 +01:00
|
|
|
const commands = client.commands.map((cmd) => cmd.data.toJSON());
|
2024-09-02 18:51:45 +01:00
|
|
|
|
2024-09-02 19:20:49 +01:00
|
|
|
// Set bot status and activity
|
|
|
|
client.user.setPresence({
|
|
|
|
activities: [{ name: "Degenerate Gamers!", type: 3 }],
|
|
|
|
status: "online",
|
|
|
|
});
|
|
|
|
|
2024-09-02 19:12:59 +01:00
|
|
|
const rest = new REST({ version: "10" }).setToken(process.env.BOT_TOKEN);
|
|
|
|
|
|
|
|
try {
|
|
|
|
await rest.put(Routes.applicationGuildCommands(client.user.id, GUIlD_ID), {
|
|
|
|
body: commands,
|
|
|
|
});
|
|
|
|
console.log("Successfully registered all application commands.");
|
|
|
|
} catch (err) {
|
|
|
|
console.error("Error registering application commands:", err);
|
|
|
|
}
|
2024-09-02 18:32:03 +01:00
|
|
|
});
|
|
|
|
|
2024-09-02 19:12:59 +01:00
|
|
|
// MongoDB connection
|
|
|
|
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 19:12:59 +01:00
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
2024-09-02 18:32:03 +01:00
|
|
|
await interaction.reply({
|
|
|
|
content: "There was an error while executing this command!",
|
|
|
|
ephemeral: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-09-02 19:12:59 +01:00
|
|
|
client.on("Error", (err) => {
|
|
|
|
console.error("Client error:", err);
|
|
|
|
});
|
|
|
|
|
2024-09-02 18:32:03 +01:00
|
|
|
client.login(process.env.BOT_TOKEN);
|