Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

300
Views
slashCommands.push(slashCommand.data.toJSON()); | TypeError: no se pueden leer las propiedades de undefined (leyendo 'toJSON')

Inicié el bot como de costumbre, en el controlador u otro archivo del comando de barra diagonal no cambié nada. alguien sabe como agrupar? Lo necesito ahora, y no puedo encontrar nada en Internet. Empecé a hacer el bot a la 1 p. m., ahora cuando escribo esto son las 10:13 p. m. y el problema apareció solo alrededor de las 9:30 p. m. No sé qué escribir a continuación, pero me siguen diciendo que tenga un buen día. / noche :D

 const fs = require('fs') const { REST } = require('@discordjs/rest') const { Routes } = require('discord-api-types/v9') const token = process.env['token']; //get the token in .env const guild = process.env['guild']; //get the guild ID in .env const application_id = process.env['application_id']; //get the application ID in .env module.exports = (client) => { const slashCommands = []; //make a variable fs.readdirSync('./slashCommands/').forEach(dir => { const slashCommandFiles = fs.readdirSync(`./slashCommands/${dir}/`).filter(file => file.endsWith('.js')); for (const file of slashCommandFiles) { const slashCommand =require(`../slashCommands/${dir}/${file}`); slashCommands.push(slashCommand.data.toJSON()); if(slashCommand.data.name) { //if the slash command file has a name client.slashCommands.set(slashCommand.data.name, slashCommand) console.log(file, '- Success') //check if the file load and log in console } else { console.log(file, '- Error') //if the file doesn't have command name, log it error in console } } }); const rest = new REST({ version: '9' }).setToken(token); (async () => { try{ console.log('Start registering application slash commands...') await rest.put( guild ? Routes.applicationGuildCommands(application_id, guild) //registered the slash command in guild : Routes.applicationCommands(application_id), //registered the slash command globally { body: slashCommands, } ); console.log('Successfully registered application slash commands.') } catch (err) { console.log(err); } })(); };
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

A uno de los archivos ubicados en este directorio le falta el objeto de datos: require( ../slashCommands/${dir}/${file} );

Una solución que detendrá el error, pero que también inutilizará el archivo, sería omitir el archivo al que le faltan datos o data.toJSON()

 for (const file of slashCommandFiles) { const slashCommand = require(`../slashCommands/${dir}/${file}`) if (!slashCommand.data || !slashCommand.data.toJSON()) continue // Carry on with code after here }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!