Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

921
Vistas
No se pueden leer las propiedades de undefined (leyendo 'get') discord.js

Así que recientemente comencé a desarrollar un bot de discord usando discord.js , y cuando intento ejecutar este comando, aparece un error cuando actualizo el bot en la línea donde ejecuto el comando ( client.commands.get('kick').execute(message, args); ).

el error es:

 TypeError: Cannot read properties of undefined (reading 'get' at Client.<anonymous> (C:\Users\Shushan\Desktop\discordbot\main.js:18:25) at Client.emit (node:events:527:28) )

Y aquí están mis archivos de código:

main.js

 const Discord = require('discord.js'); const client = new Discord.Client(); const prefix = '?'; client.once('ready', () => { console.log("Shushbot is online!"); }) client.on('message', message => { if(!message.content.startsWith(prefix) || message.author.bot) return; const args = message.content.slice(prefix.length).split(/ +/); const command = args.shift().toLowerCase(); if(command === 'kick') { client.commands.get('kick').execute(message, args); } }) client.login('SECURITY TOKEN');

kick.js

 module.exports = { name: 'kick', description: 'This Command Kicks People!', execute(message, args) { const member = message.mentions.users.first(); if(member) { const memberTarget = message.guild.members.cache.get(member.id); memberTarget.kick(); message.channel.send("This User Has Been Kicked From The Server."); } else { message.channel.send("This User Couldn't Be Kicked."); } } }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Creo que deberías verificar eso: https://discordjs.guide/creating-your-bot/command-handling.html#reading-command-files

Hasta ahora, su bot (cliente) no conoce el método de commands , e incluso si get sabe, no existe en absoluto.

Tienes que escribir algún código para crear y configurar estos comandos, ejemplo de doc:

 client.commands = new Collection(); const commandsPath = path.join(__dirname, 'commands'); const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js')); for (const file of commandFiles) { const filePath = path.join(commandsPath, file); const command = require(filePath); // Set a new item in the Collection // With the key as the command name and the value as the exported module client.commands.set(command.data.name, command); }

Puedes hacerlo de esa forma o de otra, pero en este momento tu objeto está vacío.

¡Incluso sus client.commands no están definidos!

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda