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

162
Vistas
I cant get access to the client in my command file discord.js

My reaction role file:


module.exports = {
  name: "rr",
  desc: "make a reaction role --> <",
  async run(message, client) {
    const jsEmoji = "🍏";
    const pythonEmoji = "🍍";

    let embedMessage = await message.channel.send("react for a role");
    embedMessage.react(jsEmoji);
    embedMessage.react(pythonEmoji);

    client.on("messageReactionAdd", (user, reaction) => {
      console.log("he reacted");
    });
  },
};

my bot file:

const intents = new Discord.Intents(32767);

I initialized my client here

const client = new Discord.Client({ intents: intents });

const fs = require("fs");
const commandFolders = fs.readdirSync("./Commands");
client.commands = new Discord.Collection();

commandFolders.forEach((folder) => {
  const commandFiles = fs
    .readdirSync(`./Commands/${folder}`)
    .filter((file) => file.endsWith(".js"));
  commandFiles.forEach((file) => {
    const command = require(`./Commands/${folder}/${file}`);
    client.commands.set(command.name, command);
  });
});

client.on("messageCreate", (message) => {
  if (message.author.bot || !message.content.startsWith(config.prefix)) return;

  const [command, ...args] = message.content
    .substring(config.prefix.length)
    .split(/\s+/);

I tried getting access to the client here and passing it into the run function but that didnt work.

  client.commands.forEach((cmd) =>
    command === cmd.name
      ? client.commands.get(cmd.name).run(message, args, client)
      : null
  );
});

client.login(config.token);

My Error:

    client.on("messageReactionAdd", (user, reaction) => {
           ^
TypeError: client.on is not a function

Is there another way to get access to my client?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

your arguments are wrong on command file.

You should use async run(client, message, args)

Here's a full code for you:

module.exports = {
  name: "rr",
  desc: "make a reaction role --> <",
  async run(client, message, args) {
    const jsEmoji = "🍏";
    const pythonEmoji = "🍍";

    let embedMessage = await message.channel.send("react for a role");
    embedMessage.react(jsEmoji);
    embedMessage.react(pythonEmoji);

    client.on("messageReactionAdd", (user, reaction) => {
      console.log("he reacted");
    });
  },
};
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