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

172
Vistas
How to have bot send specified user a DM?

I'm trying to create a warning command that DMs the specified user to notify them. Here is the specific code I'm trying to use:

    const user = await client.users
      .fetch(interaction.options.getString("user"), false)
      .catch(() => null);
    console.log(interaction.options.getString("user"));
    const embed = new MessageEmbed()
      .setColor("#FCE100")
      .setTitle(`⚠️ Warning!`)
      .setDescription(`${interaction.options.getString("warning")}`);
    await user.send({ embeds: embed }).catch(() => {
      interaction.channel.send(
        "Error: user not found"
      );
    });

The getString for user is correctly getting the user, as I've tested from console.log(). I can only assume the syntax is somehow wrong, although I can't seem to find the correct way to do this. The only error I'm getting is:

TypeError: Cannot read properties of null (reading 'send')
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You don't need to use .getString().
CommandInteractionOptionResolver#getString() does it for you.
Make sure that you have the user option type set to "USER" before doing the code below.

const user = interaction.options.getUser("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