Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

79
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda