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

197
Vistas
I am making a ping pong command and I am getting an error in my code

I'm making a bot and I'm getting an error saying that TypeError [ERR_INVALID_ARG_TYPE]: The "emitter" argument must be an instance of EventEmitter. Received type string ('message') on line 11. Here's my code:

const { Client, Intents } = require("discord.js");
const settings = require("./settings.json");

const client = new Client({
  intents: [
    Intents.FLAGS.GUILDS, 
    Intents.FLAGS.GUILD_MESSAGES
  ]
});

Client.on("message", (msg) => {
  // Message function
  if (msg.author.bot) return; // Ignore all bots
  if (msg.content.startsWith(settings.prefix)) return; // It always has to starts with the prefix which is '!'

  if (msg.content.startsWith(settings.prefix + "ping")) {
    // When a player does '!ping'
    msg.reply("Pong!"); // The bot will say @Author, Pong!
  }
});

Client.login(token);

This is the error I get:

throw new ERR_INVALID_ARG_TYPE('emitter', 'EventEmitter', emitter);
        ^    
TypeError [ERR_INVALID_ARG_TYPE]: The "emitter" argument must be an instance of EventEmitter. Received type string ('message')
    at new NodeError (node:internal/errors:372:5)
    at eventTargetAgnosticAddListener (node:events:1008:11)
    at Function.on (node:events:1095:3)
    at Object.<anonymous> (C:\Users\yybro\discordBot\dex.js:11:8)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47 {
      code: 'ERR_INVALID_ARG_TYPE' 

And this is my settings.json file:

{
    "clientId": "123456789012345678",
    "guildId": "876543210987654321",
    "token": "xxxxxxxxxxxxxxxxxxxxx"
}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You need to use client which is the instance of the Client class you made on line 4, and not Client which is the class itself.

Your line 11 should look like that: client.on('message', msg => { and same for client.login(token); on the last line.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Try using the import for your token like that:

const { token } = require('./settings.json')
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