Untitled
unknown
plain_text
a year ago
2.6 kB
4
Indexable
const { SlashCommandBuilder, PermissionsBitField } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('ally-remove')
.setDescription('This command kicks an entire role')
.addRoleOption(option =>
option
.setName('role-name')
.setDescription('The name of the role for users you wish to kick.')
.setRequired(true)
),
run: async ({ interaction, client, handler }) => {
const { commandName, options } = interaction;
if (commandName === 'ally-remove') {
// Get the role passed in the command
const role = options.getRole('role-name');
// Check if the bot has the necessary permissions
if (!interaction.guild.members.me.permissions.has(PermissionsBitField.Flags.KickMembers)) {
return interaction.reply({ content: 'I do not have permission to kick members!', ephemeral: true });
}
await interaction.deferReply(); // Defer the reply to handle processing time
// Get all members with the given role
const membersWithRole = interaction.guild.members.cache.filter(member => member.roles.cache.has(role.id));
if (membersWithRole.size === 0) {
return interaction.editReply({ content: `No members found with the role ${role.name}.` });
}
// Array to track kicked members
let kickedMembers = [];
let kickedCount = 0;
// Iterate over members with the specified role and kick them
for (const member of membersWithRole.values()) {
try {
await member.kick(`Kicked via /ally-remove command`);
kickedCount++;
// Track the kicked members
kickedMembers.push(`${member.user.tag} (ID: ${member.user.id})`);
} catch (err) {
console.error(`Failed to kick ${member.user.tag}: ${err.message}`);
}
}
// Debugging: Log the list of kicked members to the console
console.log('Kicked Members:', kickedMembers);
// Reply to the interaction with the list of kicked members
return interaction.editReply({
content: `Successfully kicked ${kickedCount} members with the role ${role.name}.\n` +
`Kicked members: \n${kickedMembers.join('\n')}`
});
}
},
};
Editor is loading...
Leave a Comment