MCPcopy Create free account
hub / github.com/codebymitch/TitanBot / execute

Function execute

src/commands/Leveling/levelset.js:30–88  ·  view source on GitHub ↗
(interaction, config, client)

Source from the content-addressed store, hash-verified

28 category: 'Leveling',
29
30 async execute(interaction, config, client) {
31 try {
32 await InteractionHelper.safeDefer(interaction);
33
34 const hasPermission = await checkUserPermissions(
35 interaction,
36 PermissionFlagsBits.ManageGuild,
37 'You need ManageGuild permission to use this command.'
38 );
39 if (!hasPermission) return;
40
41 const levelingConfig = await getLevelingConfig(client, interaction.guildId);
42 if (!levelingConfig?.enabled) {
43 await InteractionHelper.safeEditReply(interaction, {
44 embeds: [
45 new EmbedBuilder()
46 .setColor('#f1c40f')
47 .setDescription('The leveling system is currently disabled on this server.')
48 ],
49 flags: MessageFlags.Ephemeral
50 });
51 return;
52 }
53
54 const targetUser = interaction.options.getUser('user');
55 const newLevel = interaction.options.getInteger('level');
56
57 const member = await interaction.guild.members.fetch(targetUser.id).catch(() => null);
58 if (!member) {
59 throw new TitanBotError(
60 `User ${targetUser.id} not found in this guild`,
61 ErrorTypes.USER_INPUT,
62 'The specified user is not in this server.'
63 );
64 }
65
66 const userData = await setUserLevel(client, interaction.guildId, targetUser.id, newLevel);
67
68 await InteractionHelper.safeEditReply(interaction, {
69 embeds: [
70 createEmbed({
71 title: 'Level Set',
72 description: `Successfully set ${targetUser.tag}'s level to **${newLevel}**.\n**Total XP:** ${userData.totalXp}`,
73 color: 'success'
74 })
75 ]
76 });
77
78 logger.info(
79 `[ADMIN] User ${interaction.user.tag} set ${targetUser.tag}'s level to ${newLevel} in guild ${interaction.guildId}`
80 );
81 } catch (error) {
82 logger.error('LevelSet command error:', error);
83 await handleInteractionError(interaction, error, {
84 type: 'command',
85 commandName: 'levelset'
86 });
87 }

Callers

nothing calls this directly

Calls 7

checkUserPermissionsFunction · 0.90
getLevelingConfigFunction · 0.90
setUserLevelFunction · 0.90
createEmbedFunction · 0.90
handleInteractionErrorFunction · 0.90
safeDeferMethod · 0.80
safeEditReplyMethod · 0.80

Tested by

no test coverage detected