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

619
Vistas
JavaScript: Discord.js Error with !kick command

I have been upgrading all my previous commands to have a response with embeds instead of a normal response.

const Discord = require('discord.js')
const client = new Discord.Client({ws: {intents: Discord.Intents.ALL}});

exports.run = async (bot,message,args) => {
let member = message.mentions.members.first() || message.guild.members.cache.get(args[0])
let reason = args.slice(1).join(' ');

let embed1 = new Discord.MessageEmbed()
    .setTitle(`You Do Not Have The Permissions For This Command!`)
    .setDescription(`<@!${message.member.user.id}> you are not an Admin`)
    .setColor('#eeff00')
    .setFooter(`Bot is maintained by  BLADEZ#7296`)
let embed2 = new Discord.MessageEmbed()
    .setTitle(`InValid User`)
    .setDescription(`<@!${message.member.user.id}> please give a valid User \n **Remember** !kick [@User] [reason]`)
    .setColor('#eeff00')
    .setFooter(`Bot is maintained by  BLADEZ#7296`)
let embed3 = new Discord.MessageEmbed()
    .setTitle(`Kick Unsuccessful`)
    .setDescription(`<@!${message.member.user.id}> you can not kick this person!`)
    .setColor('#eeff00')
    .setFooter(`Bot is maintained by  BLADEZ#7296`)
let embed4 = new Discord.MessageEmbed()
    .setTitle(`Kick Successful`)
    .setDescription(`**<@!${member.user.id}>** has been **kicked** for **${reason}** by **<@!${message.author.id}>**`)
    .setColor('#eeff00')
    .setFooter(`Bot is maintained by  BLADEZ#7296`)

    
    if(!message.member.hasPermission("MANAGE_ROLES")) return message.channel.send(embed1)
    
    if(member) return message.channel.send(embed2)
   
    if(member.roles.highest.position > message.member.roles.highest.position) return message.channel.send (embed3)
    if(!reason) {reason = 'No reason given'}
    member.kick(reason)
    message.channel.send(embed4);
    console.log(`**${member.user.tag}** has been kicked for ${reason} by ${message.author.tag}`)
}

exports.help = {
    name: 'kick'
}

So this is the code I use which I haven't changed only added embeds.^

enter image description here

But I get this error ^. Kick still works just get an error if I don't include a user after !kick.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You try to use member.user.id, but if there is no member mentioned, member will be undefined.

You don't actually need to create all these embeds if you will only use one of them. Create them inside the if statements, when you're sure the values are available.

It's enough to only declare the embed and just update it.

exports.run = async (bot, message, args) => {
  let member =
    message.mentions.members.first() ||
    message.guild.members.cache.get(args[0]);
  let reason = args.slice(1).join(' ');

  let embed = new Discord.MessageEmbed()
    .setColor('#eeff00')
    .setFooter(`Bot is maintained by  BLADEZ#7296`);

  if (!message.member.hasPermission('MANAGE_ROLES')) {
    embed
      .setTitle(`You Do Not Have The Permissions For This Command!`)
      .setDescription(`<@!${message.member.user.id}> you are not an Admin`);

    return message.channel.send(embed);
  }

  // are you sure you want to check if member exists?
  // if (member) should be if (!member)
  if (!member) {
    embed
      .setTitle(`InValid User`)
      .setDescription(
        `<@!${message.member.user.id}> please give a valid User \n **Remember** !kick [@User] [reason]`,
      );
    return message.channel.send(embed);
  }

  if (member.roles.highest.position > message.member.roles.highest.position) {
    embed
      .setTitle(`Kick Unsuccessful`)
      .setDescription(
        `<@!${message.member.user.id}> you can not kick this person!`,
      );
    return message.channel.send(embed);
  }

  embed
    .setTitle(`Kick Successful`)
    .setDescription(
      `**<@!${member.user.id}>** has been **kicked** for **${reason}** by **<@!${message.author.id}>**`,
    );

  if (!reason) {
    reason = 'No reason given';
  }

  member.kick(reason);
  message.channel.send(embed);
  console.log(
    `**${member.user.tag}** has been kicked for ${reason} by ${message.author.tag}`,
  );
};

It seems to be working as expected:

enter image description here

over 4 years ago · Santiago Trujillo 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