1+ from __future__ import annotations
2+
13import asyncio
24import logging
5+ from datetime import datetime
6+ from typing import TYPE_CHECKING
37
4- from discord import Guild , Intents
8+ from discord import Guild , Intents , Interaction
59from discord .ext import commands
610from discord .utils import setup_logging
711
1115from src .commands .misc import MiscCog
1216from src .settings import Settings
1317
18+ if TYPE_CHECKING :
19+ from discord .app_commands import Command
20+ from discord .ext .commands import Context
21+
1422
1523class AeBot (commands .Bot ):
1624 watched_guild : Guild
@@ -33,6 +41,28 @@ async def on_ready(self):
3341 self .watched_guild = self .get_guild (self .settings .guild .id )
3442 self .logger .info (f"Bot ready to act on { self .watched_guild .name } " )
3543
44+ async def on_command (self , ctx : Context ):
45+ start = ctx .message .created_at
46+ duration = datetime .now (tz = start .tzinfo ) - start
47+ self .logger .info (
48+ f"Command `{ ctx .command .name } ` called by { ctx .author .name } "
49+ f"[{ duration .total_seconds ():.6f} sec]"
50+ )
51+
52+ async def on_app_command_completion (
53+ self , interaction : Interaction , command : Command
54+ ):
55+ start = interaction .created_at
56+ duration = datetime .now (tz = start .tzinfo ) - start
57+ cmd_name = (
58+ f"{ command .parent .name } { command .name } " if command .parent else command .name
59+ )
60+ self .logger .info (
61+ f"Slash command `{ cmd_name } ` "
62+ f"called by { interaction .user .name } in { interaction .channel .name } "
63+ f"[{ duration .total_seconds ():.6f} sec]"
64+ )
65+
3666
3767async def main ():
3868 async with SithClient () as client :
0 commit comments