forked from notunderctrl/discordjs-v14-series
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kick.js
82 lines (71 loc) · 2.32 KB
/
kick.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const {
Client,
Interaction,
ApplicationCommandOptionType,
PermissionFlagsBits,
} = require('discord.js');
module.exports = {
/**
*
* @param {Client} client
* @param {Interaction} interaction
*/
callback: async (client, interaction) => {
const targetUserId = interaction.options.get('target-user').value;
const reason =
interaction.options.get('reason')?.value || 'No reason provided';
await interaction.deferReply();
const targetUser = await interaction.guild.members.fetch(targetUserId);
if (!targetUser) {
await interaction.editReply("That user doesn't exist in this server.");
return;
}
if (targetUser.id === interaction.guild.ownerId) {
await interaction.editReply(
"You can't kick that user because they're the server owner."
);
return;
}
const targetUserRolePosition = targetUser.roles.highest.position; // Highest role of the target user
const requestUserRolePosition = interaction.member.roles.highest.position; // Highest role of the user running the cmd
const botRolePosition = interaction.guild.members.me.roles.highest.position; // Highest role of the bot
if (targetUserRolePosition >= requestUserRolePosition) {
await interaction.editReply(
"You can't kick that user because they have the same/higher role than you."
);
return;
}
if (targetUserRolePosition >= botRolePosition) {
await interaction.editReply(
"I can't kick that user because they have the same/higher role than me."
);
return;
}
// Kick the targetUser
try {
await targetUser.kick(reason);
await interaction.editReply(
`User ${targetUser} was kicked\nReason: ${reason}`
);
} catch (error) {
console.log(`There was an error when kicking: ${error}`);
}
},
name: 'kick',
description: 'Kicks a member from this server.',
options: [
{
name: 'target-user',
description: 'The user you want to kick.',
type: ApplicationCommandOptionType.Mentionable,
required: true,
},
{
name: 'reason',
description: 'The reason you want to kick.',
type: ApplicationCommandOptionType.String,
},
],
permissionsRequired: [PermissionFlagsBits.KickMembers],
botPermissions: [PermissionFlagsBits.KickMembers],
};