feat: new help command ui

This commit is contained in:
neoarz
2025-09-14 19:39:54 -04:00
parent 8d261089c0
commit 8152777833

View File

@@ -7,6 +7,7 @@ Version: 6.4.0
""" """
import discord import discord
from discord import app_commands
from discord.ext import commands from discord.ext import commands
from discord.ext.commands import Context from discord.ext.commands import Context
@@ -18,74 +19,131 @@ class Help(commands.Cog, name="help"):
@commands.hybrid_command( @commands.hybrid_command(
name="help", description="List all commands the bot has loaded." name="help", description="List all commands the bot has loaded."
) )
async def help(self, context: Context) -> None: @app_commands.describe(category="Choose a specific category to view its commands")
embed = discord.Embed( async def help(self, context: Context, category: str = None) -> None:
title="Help", description="List of available commands:", color=0xBEBEFE
)
category_mapping = { category_mapping = {
"help": "General", "help": "general",
"botinfo": "General", "botinfo": "general",
"serverinfo": "General", "serverinfo": "general",
"ping": "General", "ping": "general",
"invite": "General", "invite": "general",
"server": "General", "server": "general",
"8ball": "General", "8ball": "general",
"bitcoin": "General", "bitcoin": "general",
"feedback": "General", "feedback": "general",
"context_menus": "General", "context_menus": "general",
"randomfact": "Fun", "randomfact": "fun",
"coinflip": "Fun", "coinflip": "fun",
"rps": "Fun", "rps": "fun",
"kick": "Moderation", "kick": "moderation",
"ban": "Moderation", "ban": "moderation",
"nick": "Moderation", "nick": "moderation",
"purge": "Moderation", "purge": "moderation",
"hackban": "Moderation", "hackban": "moderation",
"warnings": "Moderation", "warnings": "moderation",
"archive": "Moderation", "archive": "moderation",
"sync": "owner",
"cog_management": "owner",
"shutdown": "owner",
"say": "owner",
"sync": "Owner", "testcommand": "template"
"cog_management": "Owner",
"shutdown": "Owner",
"say": "Owner",
"testcommand": "Template"
} }
category_descriptions = {
categories = {} "general": "General commands",
"fun": "Funny commands",
"moderation": "Administration commands",
"template": "Template commands",
"owner": "Owner commands"
}
for cog_name in self.bot.cogs: if category is None:
cog = self.bot.get_cog(cog_name) embed = discord.Embed(
if cog: title="Help",
commands_list = cog.get_commands() color=0xBEBEFE
for command in commands_list: )
category = category_mapping.get(cog_name.lower(), "Other")
if category == "Owner" and not (await self.bot.is_owner(context.author)): available_categories = set()
for cog_name in self.bot.cogs:
mapped_category = category_mapping.get(cog_name.lower())
if mapped_category:
if mapped_category == "owner" and not (await self.bot.is_owner(context.author)):
continue continue
available_categories.add(mapped_category)
if category not in categories:
categories[category] = [] category_list = []
for cat in sorted(available_categories):
description = command.description.partition("\n")[0] if command.description else "No description available" description = category_descriptions.get(cat, f"{cat.capitalize()} commands")
categories[category].append((command.name, description)) category_list.append(f"**/help {cat}** » {description}")
category_order = ["General", "Fun", "Moderation", "Template", "Owner", "Other"] if category_list:
for category in category_order:
if category in categories and categories[category]:
data = []
for command_name, description in sorted(categories[category]):
data.append(f"{command_name} - {description}")
help_text = "\n".join(data)
embed.add_field( embed.add_field(
name=category, value=f"```{help_text}```", inline=False name="",
value="\n".join(category_list),
inline=False
) )
await context.send(embed=embed)
return
category = category.lower()
if category not in category_descriptions:
embed = discord.Embed(
title="Error",
description=f"Category '{category}' not found. Use `/help` to see available categories.",
color=0xE02B2B
)
await context.send(embed=embed)
return
if category == "owner" and not (await self.bot.is_owner(context.author)):
embed = discord.Embed(
title="Error",
description="You don't have permission to view owner commands.",
color=0xE02B2B
)
await context.send(embed=embed)
return
commands_in_category = []
for cog_name in self.bot.cogs:
if category_mapping.get(cog_name.lower()) == category:
cog = self.bot.get_cog(cog_name)
if cog:
commands_list = cog.get_commands()
for command in commands_list:
description = command.description.partition("\n")[0] if command.description else "No description available"
commands_in_category.append((command.name, description))
if not commands_in_category:
embed = discord.Embed(
title="Error",
description=f"No commands found in category '{category}'.",
color=0xE02B2B
)
await context.send(embed=embed)
return
embed = discord.Embed(
title="Help",
color=0xBEBEFE
)
data = []
for command_name, description in sorted(commands_in_category):
data.append(f"**{command_name}** » {description}")
help_text = "\n".join(data)
embed.add_field(
name=f"{category.capitalize()} Commands",
value=help_text,
inline=False
)
await context.send(embed=embed) await context.send(embed=embed)