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

116
Vistas
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 Respuestas
Responde la pregunta

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