#JS code help needed

3 messages · Page 1 of 1 (latest)

brittle grail
#

I need with with a code

#
const path = require("node:path");
const {Client, Collection, Events, GatewayIntentBits } = require("discord.js");
const {token} = require ("./config.json");

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

client.commands = new Collection();
const commandsPath = path.join(__direname, "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(Events.ClientReady, () => {
  console.log("ready!");
  
});

client.on(Events.InteractionCreate, async (interaction) => {
  if (!interaction.isChatInputCommand()) return;

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

  if (!command) return;

  try {
    await command.execute(interaction);
  } catch (error) {
    console.error(error);
    await interaction.reply({
      content: "There was an error while executing this command!",
      ephermeral: true,
    });
  }  
});

client.login(token);```