update logs to make them nicer and set dicsord activity

This commit is contained in:
Ayden Jahola 2024-09-02 18:51:45 +01:00
parent 6ee0b874b5
commit 213fdbc582
No known key found for this signature in database
GPG key ID: 71DD90AE4AE92742
3 changed files with 28 additions and 39 deletions

View file

@ -17,7 +17,8 @@ module.exports = {
if (!code) { if (!code) {
return interaction.reply({ return interaction.reply({
content: "Please provide the verification code.", content:
"Please provide the verification code sent to your DCU email address.",
ephemeral: true, ephemeral: true,
}); });
} }

View file

@ -13,7 +13,7 @@ const transporter = nodemailer.createTransport({
module.exports = { module.exports = {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName("verify") .setName("verify")
.setDescription("Verify your account with an email address") .setDescription("Verify your account with your DCU email address")
.addStringOption((option) => .addStringOption((option) =>
option option
.setName("email") .setName("email")

View file

@ -1,14 +1,8 @@
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: [
@ -18,42 +12,40 @@ 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(path.join(__dirname, "commands")) .readdirSync(commandsPath)
.filter((file) => file.endsWith(".js")); .filter((file) => file.endsWith(".js"));
for (const file of commandFiles) { for (const file of commandFiles) {
const command = require(`./commands/${file}`); const filePath = path.join(commandsPath, file);
const command = require(filePath);
client.commands.set(command.data.name, command); client.commands.set(command.data.name, command);
} }
client.once("ready", async () => { client.once("ready", () => {
console.log(`Logges in as ${client.user.tag}`); 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`);
const commands = client.commands.map((cmd) => cmd.data.toJSON()); // Set the bot's activity here
client.user.setActivity("Degenerate Gamers", { type: "WATCHING" });
const rest = new REST({ version: "10" }).setToken(process.env.BOT_TOKEN); // Database connection (MongoDB)
mongoose
try { .connect(process.env.MONGODB_URI)
await rest.put(Routes.applicationGuildCommands(client.user.id, GUIlD_ID), { .then(() => console.log("✅ Connected to MongoDB"))
body: commands, .catch((err) => console.error("❌ Failed to connect to MongoDB", err));
});
console.log("Successfully registered application commands.");
} catch (err) {
console.error("Error registering application commands:", err);
}
}); });
// MongoDB connection
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) => { client.on("interactionCreate", async (interaction) => {
if (!interaction.isCommand()) return; if (!interaction.isCommand()) return;
@ -63,8 +55,8 @@ client.on("interactionCreate", async (interaction) => {
try { try {
await command.execute(interaction, client); await command.execute(interaction, client);
} catch (err) { } catch (error) {
console.error(err); 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,
@ -72,8 +64,4 @@ 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);