#I am getting this error
1 messages · Page 1 of 1 (latest)
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?
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined```
what is your directory structure
could you be more specific?
show me the way you have the commands folder setup rn
commands folder
ive been troubleshooting it with a smaller directory though and it still has this issue
is your working directory for console the same as your project root?
D:\VisualStudioStuff\Discord\RpgBot>
ive been running it through nodemon with npm run dev
Try using the full path maybe
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:....')
}
}
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
this was the one referencing https://discordjs.guide
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?
are you making guild commands?
yes
then try using the normal guild command manager maybe
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)
}
https://discord.js.org/#/docs/discord.js/stable/class/GuildApplicationCommandManager?scrollTo=create
Try checking this out
You can loop through it normally but just using command manager objects
thanks ill check it out