Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

618
Views
JavaScript: error de Discord.js con el comando !kick

He estado actualizando todos mis comandos anteriores para tener una respuesta con incrustaciones en lugar de una respuesta normal.

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

Entonces, este es el código que uso, que no he cambiado, solo he agregado incrustaciones.^

ingrese la descripción de la imagen aquí

Pero me sale este error ^. Kick todavía funciona, solo aparece un error si no incluyo un usuario después de !kick .

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Intenta usar member.user.id , pero si no se menciona ningún miembro, el member no estará undefined .

En realidad, no necesita crear todas estas incrustaciones si solo usará una de ellas. Créelos dentro de las declaraciones if, cuando esté seguro de que los valores están disponibles.

Es suficiente solo declarar la inserción y simplemente actualizarla.

 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}`, ); };

Parece estar funcionando como se esperaba:

ingrese la descripción de la imagen aquí

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!