MCPcopy Index your code
hub / github.com/codebymitch/TitanBot / execute

Function execute

src/commands/Moderation/kick.js:24–91  ·  view source on GitHub ↗
(interaction, config, client)

Source from the content-addressed store, hash-verified

22 category: "moderation",
23
24 async execute(interaction, config, client) {
25 try {
26 if (!interaction.member.permissions.has(PermissionFlagsBits.KickMembers)) {
27 throw new TitanBotError(
28 "User lacks permission",
29 ErrorTypes.PERMISSION,
30 "You do not have permission to kick members."
31 );
32 }
33
34 const targetUser = interaction.options.getUser("target");
35 const member = interaction.options.getMember("target");
36 const reason = interaction.options.getString("reason") || "No reason provided";
37
38 if (!targetUser) {
39 throw new TitanBotError(
40 'Missing target user',
41 ErrorTypes.USER_INPUT,
42 'You must specify a user to kick.',
43 { subtype: 'invalid_user' },
44 );
45 }
46
47 if (targetUser.id === interaction.user.id) {
48 throw new TitanBotError(
49 "Cannot kick self",
50 ErrorTypes.VALIDATION,
51 "You cannot kick yourself."
52 );
53 }
54
55 if (targetUser.id === client.user.id) {
56 throw new TitanBotError(
57 "Cannot kick bot",
58 ErrorTypes.VALIDATION,
59 "You cannot kick the bot."
60 );
61 }
62
63 if (!member) {
64 throw new TitanBotError(
65 "Target not found",
66 ErrorTypes.USER_INPUT,
67 "The target user is not currently in this server.",
68 { subtype: 'user_not_found' }
69 );
70 }
71
72 const result = await ModerationService.kickUser({
73 guild: interaction.guild,
74 member,
75 moderator: interaction.member,
76 reason,
77 });
78
79 await InteractionHelper.universalReply(interaction, {
80 embeds: [
81 successEmbed(

Callers

nothing calls this directly

Calls 4

successEmbedFunction · 0.90
handleInteractionErrorFunction · 0.90
kickUserMethod · 0.80
universalReplyMethod · 0.80

Tested by

no test coverage detected