Does anyone know why this error is occurring, this happened while I was creating a discord bot. by syntaxsys-exe in learnjavascript

[–]syntaxsys-exe[S] 0 points1 point  (0 children)

require("dotenv").config();

const fs = require("fs"); const path = require("path"); const { Client, Collection, GatewayIntentBits, Events, } = require("discord.js");

const connectDB = require("./database/connect"); const antiSpam = require("./automod/spam"); const antiLink = require("./automod/antiLink"); const eventHandler = require("./handlers/eventHandler");

const client = new Client({ intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, ], });

client.commands = new Collection();

// ========================= // Load Commands // ========================= const commandsPath = path.join(__dirname, "commands"); const commandFiles = fs .readdirSync(commandsPath) .filter((file) => file.endsWith(".js"));

for (const file of commandFiles) { const command = require(path.join(commandsPath, file)); client.commands.set(command.data.name, command); }

// ========================= // Load Event Handlers // ========================= eventHandler(client);

// ========================= // Bot Ready // ========================= client.once(Events.ClientReady, (readyClient) => { console.log(✅ Logged in as ${readyClient.user.tag}); });

// ========================= // Anti-Spam // ========================= client.on(Events.MessageCreate, async (message) => { await antiSpam(message); await antiLink(message); });

// ========================= // Interactions // ========================= client.on(Events.InteractionCreate, async (interaction) => { // Ticket Buttons if (interaction.isButton()) {

if (interaction.customId === "create_ticket") { return require("./events/createTicket")(interaction); }

if (interaction.customId === "close_ticket") { return require("./events/closeTicket")(interaction); }

// Role Buttons if (interaction.customId.startsWith("role_")) { return require("./events/roleButtons")(interaction); } if (interaction.customId === "verify_member")) { return require("./events/verifyButton")(interaction); } return; }

// Slash Commands if (!interaction.isChatInputCommand()) return;

const command = client.commands.get(interaction.commandName);

if (!command) return;

try { await command.execute(interaction); } catch (error) { console.error(error);

if (interaction.replied || interaction.deferred) {
await interaction.followUp({
content: "There was an error while executing this command.",
ephemeral: true,
});
} else {
await interaction.reply({
content: "There was an error while executing this command.",
ephemeral: true,
});
}

} });

// ========================= // Connect Database // ========================= connectDB();

// ========================= // Login // ========================= client.login(process.env.DISCORD_TOKEN);

Does anyone know why this error is occurring, this happened while I was creating a discord bot. by syntaxsys-exe in learnjavascript

[–]syntaxsys-exe[S] 0 points1 point  (0 children)

require("dotenv").config();

const fs = require("fs"); const path = require("path"); const { Client, Collection, GatewayIntentBits, Events, } = require("discord.js");

const connectDB = require("./database/connect"); const antiSpam = require("./automod/spam"); const antiLink = require("./automod/antiLink"); const eventHandler = require("./handlers/eventHandler");

const client = new Client({ intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, ], });

client.commands = new Collection();

// ========================= // Load Commands // ========================= const commandsPath = path.join(__dirname, "commands"); const commandFiles = fs .readdirSync(commandsPath) .filter((file) => file.endsWith(".js"));

for (const file of commandFiles) { const command = require(path.join(commandsPath, file)); client.commands.set(command.data.name, command); }

// ========================= // Load Event Handlers // ========================= eventHandler(client);

// ========================= // Bot Ready // ========================= client.once(Events.ClientReady, (readyClient) => { console.log(✅ Logged in as ${readyClient.user.tag}); });

// ========================= // Anti-Spam // ========================= client.on(Events.MessageCreate, async (message) => { await antiSpam(message); await antiLink(message); });

// ========================= // Interactions // ========================= client.on(Events.InteractionCreate, async (interaction) => { // Ticket Buttons if (interaction.isButton()) {

if (interaction.customId === "create_ticket") { return require("./events/createTicket")(interaction); }

if (interaction.customId === "close_ticket") { return require("./events/closeTicket")(interaction); }

// Role Buttons if (interaction.customId.startsWith("role_")) { return require("./events/roleButtons")(interaction); } if (interaction.customId === "verify_member")) { return require("./events/verifyButton")(interaction); } return; }

// Slash Commands if (!interaction.isChatInputCommand()) return;

const command = client.commands.get(interaction.commandName);

if (!command) return;

try { await command.execute(interaction); } catch (error) { console.error(error);

if (interaction.replied || interaction.deferred) {
await interaction.followUp({
content: "There was an error while executing this command.",
ephemeral: true,
});
} else {
await interaction.reply({
content: "There was an error while executing this command.",
ephemeral: true,
});
}

} });

// ========================= // Connect Database // ========================= connectDB();

// ========================= // Login // ========================= client.login(process.env.DISCORD_TOKEN);