Groups metrics commands under a common namespace

This commit is contained in:
Slipstream 2025-05-08 06:14:25 +00:00
parent 4f9d9f81a8
commit 7569be8038
2 changed files with 11 additions and 8 deletions

View File

@ -7,11 +7,13 @@ class MetricsCog(commands.Cog):
def __init__(self, bot: commands.Bot) -> None:
self.bot = bot
@app_commands.command(
name="metrics",
description="Display live bot metrics."
metrics_group = app_commands.Group(name="metrics", description="Access various bot metrics")
@metrics_group.command(
name="local",
description="Display live bot metrics (calculated locally)."
)
async def metrics(self, interaction: discord.Interaction) -> None:
async def local_metrics(self, interaction: discord.Interaction) -> None:
# Calculate live metrics.
now = datetime.utcnow()
uptime_delta = now - self.bot.launch_time

View File

@ -2,16 +2,17 @@ import discord
from discord.ext import commands
from discord import app_commands
import aiohttp
from cogs.apisync import MetricsCog # Import MetricsCog to access its group
class MetricsDisplayCog(commands.Cog):
def __init__(self, bot: commands.Bot) -> None:
self.bot = bot
@app_commands.command(
name="metrics",
@MetricsCog.metrics_group.command( # Use the group from MetricsCog
name="api", # Change name to "api"
description="Displays live bot metrics fetched from the API."
)
async def metrics(self, interaction: discord.Interaction) -> None:
async def api_metrics(self, interaction: discord.Interaction) -> None: # Rename method
# URL of your metrics API endpoint.
url = "https://api.learnhelp.cc/discord/botmetrics.json/"
@ -55,4 +56,4 @@ class MetricsDisplayCog(commands.Cog):
)
async def setup(bot: commands.Bot) -> None:
await bot.add_cog(MetricsDisplayCog(bot))
await bot.add_cog(MetricsDisplayCog(bot))