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

Function handlePrefixCommand

src/events/messageCreate.js:46–117  ·  view source on GitHub ↗
(message, client)

Source from the content-addressed store, hash-verified

44};
45
46async function handlePrefixCommand(message, client) {
47 try {
48 const guildConfig = await getGuildConfig(client, message.guild.id);
49 const prefix = guildConfig?.prefix || client.config.bot.prefix || '!';
50 const parsed = parsePrefixCommand(message.content, prefix);
51
52 if (!parsed) {
53 return;
54 }
55
56 const { commandName, args } = parsed;
57 logger.info(`Prefix command detected: ${commandName}, args: ${args.join(', ')}`);
58
59 const resolvedCommandName = resolveCommandAlias(commandName);
60 logger.info(`Resolved command name: ${resolvedCommandName}`);
61 const command = client.commands.get(resolvedCommandName);
62
63 if (!command) {
64 logger.warn(`Command not found: ${resolvedCommandName}`);
65 return;
66 }
67
68 const restriction = getPrefixRestriction(command, args, resolveSubcommandAlias);
69 if (!supportsPrefixExecution(command) || restriction.blocked) {
70 if (restriction.blocked && restriction.reason) {
71 const embed = createEmbed({
72 title: 'Slash Command Only',
73 description: `${restriction.reason}\nUse \`/${resolvedCommandName}\` instead.`,
74 color: 'info',
75 });
76 await message.channel.send({ embeds: [embed] }).catch(() => {});
77 }
78 return;
79 }
80
81 if (!(await isCommandEnabled(client, message.guild.id, resolvePrefixAccessKey(command.data, args), command.category))) {
82 const embed = createEmbed({
83 title: 'Command Disabled',
84 description: 'This command has been disabled for this server.',
85 color: 'error',
86 });
87 await message.channel.send({ embeds: [embed] }).catch(() => {});
88 return;
89 }
90
91 const mockInteractionForProtection = {
92 guildId: message.guild.id,
93 user: message.author,
94 };
95 const abuseProtection = await enforceAbuseProtection(
96 mockInteractionForProtection,
97 command,
98 resolvedCommandName,
99 );
100 if (!abuseProtection.allowed) {
101 const formattedCooldown = formatCooldownDuration(abuseProtection.remainingMs);
102 const embed = createEmbed({
103 title: 'Command Cooldown',

Callers 1

executeFunction · 0.85

Calls 12

getGuildConfigFunction · 0.90
parsePrefixCommandFunction · 0.90
resolveCommandAliasFunction · 0.90
getPrefixRestrictionFunction · 0.90
supportsPrefixExecutionFunction · 0.90
createEmbedFunction · 0.90
isCommandEnabledFunction · 0.90
resolvePrefixAccessKeyFunction · 0.90
enforceAbuseProtectionFunction · 0.90
formatCooldownDurationFunction · 0.90
executePrefixCommandFunction · 0.90
getMethod · 0.45

Tested by

no test coverage detected