Skip to content

Commit 3ad9c2b

Browse files
authored
Fix the logging of subcommands (#20)
1 parent d6594fe commit 3ad9c2b

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

discord/ext/prometheus/prometheus_cog.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from prometheus_client import start_http_server, Counter, Gauge
33
from discord.ext import commands, tasks
44
from discord import Interaction, InteractionType, AutoShardedClient
5+
from discord.app_commands.commands import Command
56

67
log = logging.getLogger("prometheus")
78

@@ -124,7 +125,18 @@ async def on_interaction(self, interaction: Interaction):
124125
interaction.type == InteractionType.application_command
125126
and interaction.command
126127
):
127-
command_name = interaction.command.name
128+
if isinstance(interaction.command, Command):
129+
# Slash Command
130+
command_name = ""
131+
parent = interaction.command.parent
132+
while parent is not None:
133+
# Handle subcommands
134+
command_name += parent.name + " "
135+
parent = parent.parent
136+
command_name += interaction.command.name
137+
else:
138+
# Context Menu Button
139+
command_name = interaction.command.name
128140

129141
ON_INTERACTION_COUNTER.labels(
130142
shard_id, interaction.type.name, command_name

0 commit comments

Comments
 (0)