mirror of
https://github.com/aydenjahola/discord-multipurpose-bot.git
synced 2024-11-25 02:05:56 +00:00
I did an opsie and removed comamnds regiseteration with discord api
This commit is contained in:
parent
81805183f6
commit
b1395eb032
1 changed files with 36 additions and 17 deletions
47
index.js
47
index.js
|
@ -1,8 +1,14 @@
|
||||||
require("dotenv").config();
|
require("dotenv").config();
|
||||||
|
const {
|
||||||
|
Client,
|
||||||
|
GatewayIntentBits,
|
||||||
|
Collection,
|
||||||
|
REST,
|
||||||
|
Routes,
|
||||||
|
} = require("discord.js");
|
||||||
|
const mongoose = require("mongoose");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const { Client, GatewayIntentBits, Collection } = require("discord.js");
|
|
||||||
const mongoose = require("mongoose");
|
|
||||||
|
|
||||||
const client = new Client({
|
const client = new Client({
|
||||||
intents: [
|
intents: [
|
||||||
|
@ -12,21 +18,20 @@ const client = new Client({
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const GUIlD_ID = process.env.GUILD_ID;
|
||||||
|
|
||||||
client.commands = new Collection();
|
client.commands = new Collection();
|
||||||
|
|
||||||
// Load command files dynamically
|
|
||||||
const commandsPath = path.join(__dirname, "commands");
|
|
||||||
const commandFiles = fs
|
const commandFiles = fs
|
||||||
.readdirSync(commandsPath)
|
.readdirSync(path.join(__dirname, "commands"))
|
||||||
.filter((file) => file.endsWith(".js"));
|
.filter((file) => file.endsWith(".js"));
|
||||||
|
|
||||||
for (const file of commandFiles) {
|
for (const file of commandFiles) {
|
||||||
const filePath = path.join(commandsPath, file);
|
const command = require(`./commands/${file}`);
|
||||||
const command = require(filePath);
|
|
||||||
client.commands.set(command.data.name, command);
|
client.commands.set(command.data.name, command);
|
||||||
}
|
}
|
||||||
|
|
||||||
client.once("ready", () => {
|
client.once("ready", async () => {
|
||||||
console.log(`\n==============================`);
|
console.log(`\n==============================`);
|
||||||
console.log(`🤖 Logged in as ${client.user.tag}`);
|
console.log(`🤖 Logged in as ${client.user.tag}`);
|
||||||
console.log(`==============================`);
|
console.log(`==============================`);
|
||||||
|
@ -36,15 +41,25 @@ client.once("ready", () => {
|
||||||
});
|
});
|
||||||
console.log(`\n==============================\n`);
|
console.log(`\n==============================\n`);
|
||||||
|
|
||||||
// Set the bot's activity here
|
const commands = client.commands.map((cmd) => cmd.data.toJSON());
|
||||||
client.user.setActivity({ type: "WATCHING", name: "Degenerate Gamers" });
|
|
||||||
|
|
||||||
// Database connection (MongoDB)
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// MongoDB connection
|
||||||
mongoose
|
mongoose
|
||||||
.connect(process.env.MONGODB_URI)
|
.connect(process.env.MONGODB_URI)
|
||||||
.then(() => console.log("✅ Connected to MongoDB"))
|
.then(() => console.log("✅ Connected to MongoDB"))
|
||||||
.catch((err) => console.error("❌ Failed to connect to MongoDB", err));
|
.catch((err) => console.error("❌ Failed to connect to MongoDB", err));
|
||||||
});
|
|
||||||
|
|
||||||
client.on("interactionCreate", async (interaction) => {
|
client.on("interactionCreate", async (interaction) => {
|
||||||
if (!interaction.isCommand()) return;
|
if (!interaction.isCommand()) return;
|
||||||
|
@ -55,8 +70,8 @@ client.on("interactionCreate", async (interaction) => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await command.execute(interaction, client);
|
await command.execute(interaction, client);
|
||||||
} catch (error) {
|
} catch (err) {
|
||||||
console.error(error);
|
console.error(err);
|
||||||
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,
|
||||||
|
@ -64,4 +79,8 @@ client.on("interactionCreate", async (interaction) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
client.on("Error", (err) => {
|
||||||
|
console.error("Client error:", err);
|
||||||
|
});
|
||||||
|
|
||||||
client.login(process.env.BOT_TOKEN);
|
client.login(process.env.BOT_TOKEN);
|
||||||
|
|
Loading…
Reference in a new issue