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

133
Views
TypeError: bot.commands.get(...).run no es una función

Acabo de intentar crear un controlador de comandos en discord.js y cada vez que ejecuto el bot, arroja

TypeError: bot.commands.get(...).run no es una función

Aquí está la parte inferior del código sobre dónde está ocurriendo el error.

 bot.on("message", async message => { if(message.author.bot) return; if(message.channel.type === 'dm') return; if(message.content.startsWith(prefix)) { const args = message.content.slice(prefix.length).trim().split(/ +/); const command = args.shift().toLowerCase(); if(!bot.commands.has(command)) return; try { bot.commands.get(command).run(bot, message, args); } catch (error){ console.error(error); } } }) bot.login(token);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Parece que su controlador de comandos está un poco incompleto. Así es como tengo la configuración mía, puedes probarlo y decirme si funciona (lo explico todo con los comentarios:

 // your bot.js or main.js file const bot = new Discord.Client(); // I setup the bot client bot.commands = new Discord.Collection(); // I create a collection with all the commands const commandsFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js')); // In my project tree, I define all the files with the .js extension in this folder as command files. I will add a file (.js) to this folder for each command I want to create. For example, there will be './commands/ping.js' inside. for(const file of commandsFiles){ const command = require(`./commands/${file}`); client.commands.set(command.name, command); } // For each command file detected, I add it's name and it's path to my client.commands collection client.on('message', message => { if(message.author.bot) return; if(message.channel.type === 'dm') return; if(message.content.startsWith(prefix)) { const args = message.content.slice(prefix.length).trim().split(/ +/); const command = args.shift().toLowerCase(); if(!bot.commands.has(command)) return; // if the collection doesn't have a command with this name, return try { bot.commands.get(command).run(bot, message, args); // I get the command object defined previously in the 'for' loop, and I execute the run function with bot, message and args as arguments } catch (error){ console.error(error); } } }

Ahora que ha configurado su controlador de comandos, para cada comando que desee crear, agregue un archivo dentro de la carpeta ./commands/ (por ejemplo, ./commands/ping.js , no olvide la parte .js) . En este archivo recién creado, escriba:

 module.exports = { name : 'ping', description : 'Ping command', run(bot, message, args) { // the code to be executed }

Aquí puede ver que definimos un objeto, que será utilizado por el controlador de comandos.

Cuando hacemos client.commands.set(command.name, command) (en bot.js o main.js), usamos el nombre definido aquí.

Cuando hacemos client.commands.get(command).run(bot, message, args) , ejecutamos la función de run definida dentro del objeto module.export del archivo de comando de destino.

No dudes en decirme si hay algo que no entiendas.

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!