#I am getting this error

1 messages · Page 1 of 1 (latest)

bold oracle
#

Can you send the code?

void meadow
#

Yeah

#

its for the slash commands handler

#
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const { token } = require('./config.json');
const fs = require('node:fs');

const commands = [];
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));

// Place your client and guild ids here
const clientId = '123456789012345678';
const guildId = '876543210987654321';

for (const file of commandFiles) {
    const command = require(`./commands/${file}`);
    commands.push(command.data.toJSON());
}

const rest = new REST({ version: '9' }).setToken(token);

(async () => {
    try {
        console.log('Started refreshing application (/) commands.');

        await rest.put(
            Routes.applicationGuildCommands(clientId, guildId),
            { body: commands },
        );

        console.log('Successfully reloaded application (/) commands.');
    } catch (error) {
        console.error(error);
    }
})();

#

any idea why it isnt letting js commands.data.toJSON() run?

bold oracle
#

try console logging command.data

#

also i think it should be command.data

void meadow
#
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined```
bold oracle
#

what is your directory structure

void meadow
#

could you be more specific?

bold oracle
#

show me the way you have the commands folder setup rn

void meadow
bold oracle
#

commands folder

void meadow
#

ive been troubleshooting it with a smaller directory though and it still has this issue

bold oracle
#

is your working directory for console the same as your project root?

void meadow
#

D:\VisualStudioStuff\Discord\RpgBot>

#

ive been running it through nodemon with npm run dev

bold oracle
#

Try using the full path maybe

void meadow
#

full path isnt working

#

could it be because of how I laid things out inside my files inside the commands folder?

#
//help.js content
const { SlashCommandBuilder } = require("@discordjs/builders");

module.exports = {
    data : new SlashCommandBuilder()
        .setName('help')
        .setDescription('Replies with your available commands!'),
    
    async execute(interaction) {
        interaction.channel.send('Here are your commands:....')
    }
}
bold oracle
#

hmm not sure what's going wrong here

#

maybe try using the normal command manager instead of rest?

#

i havent used rest much so

#

I've been fine using the normal djs command manager

void meadow
#

I also tried referencing other sites and things but they all have crashed when I tried running them

#

all around the same point

#

If I have only a handful of commands to define can I just hard code them in?

bold oracle
#

are you making guild commands?

void meadow
#

yes

bold oracle
#

then try using the normal guild command manager maybe

void meadow
#

I only need to really program in two slash commands since the rest of the bot is operating off of a user interaction

#

My bot is working fine with my regular command handler for non-slash commands, I was just hoping to implement slash commands as well

#

const prefix = "!"

client.commands = new DiscordJS.Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'))



for (file of commandFiles) {
    const commandName = file.split(".")[0] //getting the command name
    const command = require(`./commands/${commandName}`)
    client.commands.set(commandName, command)
}
bold oracle
#

Try checking this out

#

You can loop through it normally but just using command manager objects

void meadow
#

thanks ill check it out