#Tehirion : Help with Get Error.

1 messages · Page 1 of 1 (latest)

eternal turret
#

this is the code that is erroring

const { Events } = require('discord.js');

module.exports = {
    name: Events.InteractionCreate,
    async execute(interaction) {
        if (!interaction.isChatInputCommand()) return;

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

        if (!command) {
            console.error(`No command matching ${interaction.commandName} was found.`);
            return;
        }

        try {
            await command.execute(interaction);
        } catch (error) {
            console.error(`Error executing ${interaction.commandName}`);
            console.error(error);
        }
    },
};
#

Tehirion : Help with Get Error.

#

@late anvil I thought I'd do this so that the discussion isn't conveluted

late anvil
eternal turret
eternal turret
#

This is my deploying of command code

const { REST, Routes } = require("discord.js");
require("dotenv").config();
const fs = require("node:fs");
const path = require("node:path");

const token = process.env.TOKEN;
const clientId = process.env.CLIENT_ID;
const guildId = process.env.GUILD_ID;

const commands = [];
// Grab all the command files from the commands directory you created earlier
const commandsPath = path.join(__dirname, "commands");
const commandFiles = fs
  .readdirSync(commandsPath)
  .filter((file) => file.endsWith(".js"));

// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
for (const file of commandFiles) {
  const command = require(`./commands/${file}`);
  commands.push(command.data.toJSON());
}

// Construct and prepare an instance of the REST module
const rest = new REST({ version: "10" }).setToken(token);

// and deploy your commands!
(async () => {
  try {
    console.log(
      `Started refreshing ${commands.length} application (/) commands.`
    );

    // The put method is used to fully refresh all commands in the guild with the current set
    const data = await rest.put(
      Routes.applicationGuildCommands(clientId, guildId),
      { body: commands }
    );

    console.log(
      `Successfully reloaded ${data.length} application (/) commands.`
    );
  } catch (error) {
    // And of course, make sure you catch and log any errors!
    console.error(error);
  }
})();
late anvil
eternal turret
late anvil
#

It should be in index.js if you’re following the guide.

eternal turret
#

AH Okay

#

one moment

late anvil
#

Your error says it’s undefined so you need to define it and then load the commands into it so you can execute them.

eternal turret
#
const fs = require("node:fs");
const path = require("node:path");
const { Client, Collection, Events, GatewayIntentBits } = require("discord.js");
require("dotenv").config();

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

const eventsPath = path.join(__dirname, "events");
const eventFiles = fs
  .readdirSync(eventsPath)
  .filter((file) => file.endsWith(".js"));

for (const file of eventFiles) {
  const filePath = path.join(eventsPath, file);
  const event = require(filePath);
  if (event.once) {
    client.once(event.name, (...args) => event.execute(...args));
  } else {
    client.on(event.name, (...args) => event.execute(...args));
  }
}

client.login(process.env.TOKEN);
#

This is my complete Index code

late anvil
pastel mesaBOT
#

guide Creating Your Bot: Loading command files
read more

late anvil
#

That page will walk you thru that command loading

eternal turret
#

Thanks @late anvil I do appreciate you helping me out in here!

#

it's the client Commands = new collections that i've missed isnt it?

eternal turret
#

Right I'm starting to see it now

late anvil
#

You’ve basically told discord 'hey I have these commands' and discord is like 👍🏻.
You run a command and discord sends it to you as an interaction. But your client doesn’t know how to run them.

eternal turret
late anvil
eternal turret
late anvil
eternal turret
#

Well I hope I can find the cookies 😂

late anvil
#

Should be just that little section loading the command files into the commands collection.

eternal turret
#

@late anvil So this seems to have appeared

#

The Commands have doubled up and I can't seem to figure why

#

One bit of good news is that the commands are working again

late anvil
late anvil
eternal turret
eternal turret