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

82
Vistas
How can I change this kick command fully to get a reply when you try to kick a member that is not in the server?

So I have this kick command I have coded and it is working perfectly fine. My question is, how can I change the command so that I get a reply saying as an example "You can't kick this user since they are not in this server" or so.

Here is my code:

const { Client, CommandInteraction, MessageEmbed } = require("discord.js");

module.exports = {
    name: "kick",
    description: "Kick a member",
    userPermission: ["KICK_MEMBERS"],
    options: [
        {
            name: "target",
            description: "target to kick",
            type: "USER",
            required: true
        },
        {
            name: "reason",
            description: "reason for this kick",
            type: "STRING",
            required: false,
        }
    ],
    /**
     * 
     * @param {Client} client 
     * @param {CommandInteraction} interaction 
     * @param {String} args 
     */
    execute: async(interaction, client, args) => {
        const { options, member, guild } = interaction;

        const target = options.getMember("target");
        const reason = options.getString("reason") || "No reason provided";

        if(!target.roles.highest.position >= member.roles.highest.position) return interaction.reply({content: "You can't take action on this user as their role is higher than yours!",
    });

    await target.send({embeds: [new MessageEmbed().setColor("AQUA").setTitle("🚪 Kicked").setAuthor(target.user.tag, target.user.avatarURL({dynamic: true, size: 512})).setDescription(`You have been kicked from **${guild.name}**!\nReason: \`${reason}\``).setFooter(`ID: ${target.user.id}`)]});

    target.kick(reason);

    interaction.reply({embeds: [new MessageEmbed().setColor("GREEN").setTitle("🚪 Kick").setAuthor(target.user.tag, target.user.avatarURL({dynamic: true, size: 512})).setDescription(`**${target.user.tag}** has successfully been kicked from **${guild.name}**!\n**Reason:** \`${reason}\``).setFooter(`ID: ${target.user.id}`)]});
    },
};
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Because this is a slash command and requires a USER here:

name: "target",
description: "target to kick",
type: "USER",
required: true

Then there can never exist a possibility of this command running without the user being in the guild. The command would error before it was sent.

Edit:

Also your line

const target = options.getMember("target");

Should be

const target = options.getUser("target");

You would need to get the member using the below:

const targetMember = guild.members.cache.find(member => member.id === target)

Then every line below that where target is used change to targetMember

Edit answering question in comments:

To kick/ban someone not in the guild

const targetMember = guild.members.cache.find(member => member.id === target)

if (targetMember = undefined) {
// code to kick/ban
} else {
// normal code
}
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