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

297
Views
¿Por qué el argumento de 'interacción' no está definido en este script de registro de archivos?

Estoy aprendiendo (semi-exitosamente) cómo usar los nuevos comandos de barra en Discord.js, un módulo de node.js para interactuar con la API del bot de Discord. Por lo que puedo ver, esto es estrictamente un problema con el código base de Javascript, ¡y no se requiere conocimiento de Discord.js para ayudar a mi pequeño problema bastante molesto!

El código es para recuperar archivos de eventos y ejecutarlos. El problema es que cada vez que se ejecuta el archivo interactionCreate.js , el argumento de interaction parece no estar definido.

Si es necesario, la estructura del archivo es la siguiente:

 project-folder/ ├── index.js ├── events/ └── interactionCreate.js

Aquí está index.js :

 const eventFiles = fs.readdirSync('./events').filter(file => file.endsWith('.js')); for (const file of eventFiles) { const event = require(`./events/${file}`); if (event.once) { client.once(event.name, (...args) => event.execute(...args)); } else { client.on(event.name, (...args) => event.execute(...args)); } }

... y aquí está interactionCreate.js :

 module.exports = { name: 'interactionCreate', async execute(client, interaction) { if (!interaction.isCommand()) 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.', ephemeral: true }); } }, };

No estoy completamente seguro de si esto es relevante, pero así es como se ve el código cuando no está en módulos separados. Por supuesto, la recuperación del archivo de eventos no es necesaria aquí.

index.js (before modularisation) :

 client.on('interactionCreate', async interaction => { if (!interaction.isCommand()) 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.', ephemeral: true }); } });

Nuevamente, no estoy seguro de si esto es necesario, pero este es uno de los mensajes de error que recibiría.

 C:\path\to\files\project-folder\events\interactionCreate.js:4 if (!interaction.isCommand()) return; ^ TypeError: Cannot read properties of undefined (reading 'isCommand')

No tengo mucha experiencia haciendo preguntas aquí, así que si necesitas algo más, ¡avísame! Con mucho gusto responderé a su respuesta o actualizaré la pregunta. ¡Muchas gracias!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Su declaración es así:

 async execute(client, interaction) { //... }

Y el evento interactionCreate solo proporciona 1 parámetro ( interaction ). Si todos sus eventos estuvieran en un orden de parámetro client, rest, of, the, args , este sería el enfoque:

 if (event.once) { client.once(event.name, (...args) => event.execute(client, ...args)); } else { client.on(event.name, (...args) => event.execute(client, ...args)); }
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!