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

219
Vistas
Check if first argument is a mention

I'm coding a discord bot and I'm trying to make a kick command right now. I managed to find how to check if there's any mention in the command message with message.mentions.members.first() but I couldn't find anything to check if a specific argument is a mention.

Code I have so far:

module.exports = {
    name: "kick", 
    category: "moderation",
    permissions: ["KICK_MEMBERS"], 
    devOnly: false, 
    run: async ({client, message, args}) => {
        if (args[0]){
            if(message.mentions.members.first())
                message.reply("yes ping thing")
            else message.reply("``" + args[0] + "`` isn't a mention. Please mention someone to kick.")
        }
        else
            message.reply("Please specify who you want to kick: g!kick @user123")
    }
}

I looked at the DJS guide but couldn't find how.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

MessageMentions has a USERS_PATTERN property that contains the regular expression that matches the user mentions (like <@!813230572179619871>). You can use it with String#match, or RegExp#test() to check if your argument matches the pattern.

Here is an example using String#match:

// make sure to import MessageMentions
const { MessageMentions } = require('discord.js')

module.exports = {
  name: 'kick',
  category: 'moderation',
  permissions: ['KICK_MEMBERS'],
  devOnly: false,
  run: async ({ client, message, args }) => {
    if (!args[0])
      return message.reply('Please specify who you want to kick: `g!kick @user123`')

    // returns null if args[0] is not a mention, an array otherwise
    let isMention = args[0].match(MessageMentions.USERS_PATTERN)

    if (!isMention)
      return message.reply(`First argument (_\`${args[0]}\`_) needs to be a member: \`g!kick @user123\``)

    // kick the member
    let member = message.mentions.members.first()
    if (!member.kickable)
      return message.reply(`You can't kick ${member}`)

    try {
      await member.kick()
      message.reply('yes ping thing')
    } catch (err) {
      console.log(err)
      message.reply('There was an error')
    }
  }
}
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