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

350
Vistas
Discord bot - send DM to mentioned user

I want make bot that will send message to user that I mention for example I will type !hello @thomas#5555

And bot will send DM message "hello" to this user

if(message.content.startsWith(prefix + "sendHello")){
    const taggedUser = message.mentions.users.first();
    const user = client.users.cache.get(taggedUser.id);
    user.send('Hello');
    }

What's wrong? Keep getting this: "ReferenceError: client is not defined"

I defined client on the top of the code like this: "const Client = new Disocrd.Client();"

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

0

Since you defined your client as Client, you need to use that instead of client. You could also use message.client to access it from the message object.

about 4 years ago · Juan Pablo Isaza Denunciar

0

First make sure you are initializing your Client correctly.

Try:

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

With discord.js v13 you need to add the intents you want your Client to receive. The Intents.FLAGS.GUILDS intents option is necessary for your client to work properly. You can see all Intents here.

Also for your command code, if someone tagged a User you don't need to fetch the User again. Just use the taggedUser variable.

const taggedUser = message.mentions.users.first(); // get User
if (!taggedUser) return message.channel.send('Please mention a user to fetch.'); // Check to see if a User was tagged.
taggedUser.send('Hi') // send to User
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