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

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

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 Relatório

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 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