Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

173
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda