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

104
Visualizações
How can I make a code which is triggered by someone mentioning certain user and warns the triggering user

This is a code idea I had to make code that is triggered by mentioning a certain user and warning the triggered user, but it just doesn't work

const Client = require("./Structures/Client.js");

const config = require("./Data/config.json");

const client = new Client();

client.on("messageCreate", message => {
  if(message.content == "<@USER2ID>") message.reply("User1#1234 has mentioned User2#1234");
});

client.start(config.token);
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You should be using the message.mentions object instead of getting the content of the message. Also is client.start not a function. You should use the client.login function instead. You've also forgot to mention the intents that you want to use. Please take a look at the following example:

const {Client, Intents} = require('discord.js'); // Import the client and intents
const config = require('./Data/config.json'); // Import the config

const client = new Client({
    intents: [Intents.FLAGS.GUILD_MESSAGES] // Uses the intent 'GUILD_MESSAGES' to be able to get the messages
}); // Creates the client

client.on('messageCreate', message => { // Creates an event listener
    if(message.author.bot || message.channel.type === `DM`) return; // Returns when the author is a bot or if the message is being send in a DM

    if(message.mentions.members.get(`0123456789`)){ // If the user with the user id '0123456789' has been mentioned in the message
       message.reply(`The user ${message.mentions.members.get(`0123456789`).user.tag} has been mentioned`); // Sends the reply
   }
});

client.login(config.token); // Login to the bot
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