const { Client, Interaction, ApplicationCommandOptionType, PermissionFlagsBits, SlashCommandBuilder, } = require("discord.js"); async function handleKickCommand(interaction) { if (!interaction.member.permissions.has(PermissionFlagsBits.KickMembers)) { await interaction.reply({ content: "You do not have permission to kick members.", ephemeral: true, }); return; } const targetID = interaction.options.get('user').value; const reason = interaction.options.get("reason")?.value || "No reason provided"; await interaction.deferReply(); const targetUser = await interaction.guild.members.fetch(targetID) if (!targetUser) { await interaction.editReply('That user does not exist in this server'); return; } if (targetUser.id === interaction.guild.ownerId) { await interaction.editReply("I can't kick the server owner") return; } if (targetUser.id === interaction.guild.members.me) { await interaction.editReply("I can't kick myself") return; } const targetUserRolePostion = targetUser.roles.highest.postion; const requestUserRolePostion = interaction.member.roles.highest.postion const botRolePostion = interaction.guild.members.me.roles.highest.postion if (targetUserRolePostion >= requestUserRolePostion) { await interaction.editReply("You can't kick someone that has the same/higher role than you") return; } if (targetUserRolePostion >= botRolePostion) { await interaction.editReply("I can't kick that user because they have the same/higher role than me.") return; } try { await targetUser.kick({ reason }) await interaction.editReply(`User ${targetUser} was kicked. Reason: ${reason}`) } catch (error) { console.error('There was a problem kicking: ', error) } } module.exports = { data: new SlashCommandBuilder() .setName("kick") .setDescription("Kicks the specified user") .addUserOption((option) => option.setName("user").setDescription("Mention the user to kick").setRequired(true)) .addStringOption((option) => option.setName('reason').setDescription('Specify the reason for kicking').setRequired(false)) .setDefaultMemberPermissions(PermissionFlagsBits.KickMembers), async execute(interaction) { try { handleKickCommand(interaction) } catch (error) { console.error('There was an error in kicking:', error) } } };