feat: Help Command is finally finished

when new commands are added its a simple add
This commit is contained in:
neoarz
2025-09-14 21:54:04 -04:00
parent d7f1ce86c2
commit f2c26db481
2 changed files with 33 additions and 27 deletions

View File

@@ -1,11 +1,3 @@
"""
Copyright © Krypton 2019-Present - https://github.com/kkrypt0nn (https://krypton.ninja)
Description:
🐍 A simple template to start to code your own and personalized Discord bot in Python
Version: 6.4.0
"""
import discord
from discord import app_commands
from discord.ext import commands
@@ -16,10 +8,33 @@ class Help(commands.Cog, name="help"):
def __init__(self, bot) -> None:
self.bot = bot
async def category_autocomplete(
self,
interaction: discord.Interaction,
current: str,
) -> list[app_commands.Choice[str]]:
categories = ["general", "fun", "moderation", "template"]
if await self.bot.is_owner(interaction.user):
categories.append("owner")
suggestions = []
for category in categories:
if current.lower() in category.lower():
suggestions.append(
app_commands.Choice(
name=f"{category.capitalize()} Commands",
value=category
)
)
return suggestions[:25]
@commands.hybrid_command(
name="help", description="List all commands the bot has loaded."
)
@app_commands.describe(category="Choose a specific category to view its commands")
@app_commands.autocomplete(category=category_autocomplete)
async def help(self, context: Context, category: str = None) -> None:
category_mapping = {
@@ -65,8 +80,9 @@ class Help(commands.Cog, name="help"):
if category is None:
embed = discord.Embed(
title="Help",
color=0xBEBEFE
color=0x808080
)
embed.set_author(name="Help", icon_url="https://yes.nighty.works/raw/HP69uM.png")
available_categories = set()
for cog_name in self.bot.cogs:
@@ -99,7 +115,7 @@ class Help(commands.Cog, name="help"):
embed = discord.Embed(
title="Error",
description=f"Category '{category}' not found. Use `/help` to see available categories.",
color=0xE02B2B
color=0x808080
)
if context.interaction:
await context.interaction.response.send_message(embed=embed, ephemeral=True)
@@ -111,7 +127,7 @@ class Help(commands.Cog, name="help"):
embed = discord.Embed(
title="Error",
description="You don't have permission to view owner commands.",
color=0xE02B2B
color=0x808080
)
if context.interaction:
await context.interaction.response.send_message(embed=embed, ephemeral=True)
@@ -133,7 +149,7 @@ class Help(commands.Cog, name="help"):
embed = discord.Embed(
title="Error",
description=f"No commands found in category '{category}'.",
color=0xE02B2B
color=0x808080
)
if context.interaction:
await context.interaction.response.send_message(embed=embed, ephemeral=True)
@@ -142,21 +158,19 @@ class Help(commands.Cog, name="help"):
return
embed = discord.Embed(
title=f"Help » {category.capitalize()}",
color=0xBEBEFE
title=f"/help » {category.lower()}",
color=0x808080
)
embed.set_author(name="Help", icon_url="https://yes.nighty.works/raw/HP69uM.png")
data = []
for command_name, description in sorted(commands_in_category):
data.append(f"**{command_name}** » {description}")
data.append(f"**/{command_name}** » {description}")
help_text = "\n".join(data)
embed.add_field(
name="",
value=help_text,
inline=False
)
if context.interaction:
await context.interaction.response.send_message(embed=embed, ephemeral=True)
else:
@@ -164,4 +178,4 @@ class Help(commands.Cog, name="help"):
async def setup(bot) -> None:
await bot.add_cog(Help(bot))
await bot.add_cog(Help(bot))

View File

@@ -1,11 +1,3 @@
"""
Copyright © Krypton 2019-Present - https://github.com/kkrypt0nn (https://krypton.ninja)
Description:
🐍 A simple template to start to code your own and personalized Discord bot in Python
Version: 6.4.0
"""
import discord
from discord.ext import commands
from discord.ext.commands import Context