first commit
This commit is contained in:
92
commands/moderation/ban.js
Normal file
92
commands/moderation/ban.js
Normal file
@ -0,0 +1,92 @@
|
||||
const {
|
||||
Client,
|
||||
Interaction,
|
||||
ApplicationCommandOptionType,
|
||||
PermissionFlagsBits,
|
||||
SlashCommandBuilder,
|
||||
} = require("discord.js");
|
||||
|
||||
async function handleBanCommand(interaction) {
|
||||
if (!interaction.member.permissions.has(PermissionFlagsBits.BanMembers)) {
|
||||
await interaction.reply({
|
||||
content: "You do not have permission to ban 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 is not in the server");
|
||||
return;
|
||||
}
|
||||
|
||||
if (targetUser.id === interaction.guild.ownerId) {
|
||||
await interaction.editReply("I can't ban the server owner");
|
||||
return;
|
||||
}
|
||||
|
||||
if (targetUser.id === interaction.guild.members.me) {
|
||||
await interaction.editReply("I cant't ban myself");
|
||||
return;
|
||||
}
|
||||
|
||||
const targetUserRolePostion = targetUser.roles.highest.postion; // check the user highest role
|
||||
const requestUserRolePostion = interaction.member.roles.highest.postion; // check the user issuing the command is higher than the target
|
||||
const botRolePostion = interaction.guild.members.me.roles.highest.postion; // check the bot has permissions
|
||||
|
||||
if (targetUserRolePostion >= requestUserRolePostion) {
|
||||
await interaction.editReply(
|
||||
"You can't ban someone that has the same/higher role than you."
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (targetUserRolePostion >= botRolePostion) {
|
||||
await interaction.editReply(
|
||||
"I can't ban that user because they have the same/higher role than me."
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await targetUser.ban({ reason });
|
||||
await interaction.editReply(
|
||||
`User ${targetUser} was banned. Reason: ${reason}`
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("There was an error banning the target: ", error);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("ban")
|
||||
.setDescription("Bans the specified user")
|
||||
.addUserOption((option) =>
|
||||
option
|
||||
.setName("user")
|
||||
.setDescription("Mention the user to ban")
|
||||
.setRequired(true)
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName("reason")
|
||||
.setDescription("Specify the reason for banning")
|
||||
.setRequired(false)
|
||||
)
|
||||
.setDefaultMemberPermissions(PermissionFlagsBits.BanMembers),
|
||||
async execute(interaction) {
|
||||
try {
|
||||
handleBanCommand(interaction);
|
||||
} catch (error) {
|
||||
console.error("There was an error in banning: ", error);
|
||||
}
|
||||
},
|
||||
};
|
||||
75
commands/moderation/kick.js
Normal file
75
commands/moderation/kick.js
Normal file
@ -0,0 +1,75 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user