mirror of
https://github.com/neoarz/Syntrel.git
synced 2025-12-25 11:40:12 +01:00
feat: Help Command is finally finished
when new commands are added its a simple add
This commit is contained in:
@@ -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
|
import discord
|
||||||
from discord import app_commands
|
from discord import app_commands
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
@@ -16,10 +8,33 @@ class Help(commands.Cog, name="help"):
|
|||||||
def __init__(self, bot) -> None:
|
def __init__(self, bot) -> None:
|
||||||
self.bot = bot
|
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(
|
@commands.hybrid_command(
|
||||||
name="help", description="List all commands the bot has loaded."
|
name="help", description="List all commands the bot has loaded."
|
||||||
)
|
)
|
||||||
@app_commands.describe(category="Choose a specific category to view its commands")
|
@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:
|
async def help(self, context: Context, category: str = None) -> None:
|
||||||
|
|
||||||
category_mapping = {
|
category_mapping = {
|
||||||
@@ -65,8 +80,9 @@ class Help(commands.Cog, name="help"):
|
|||||||
if category is None:
|
if category is None:
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
title="Help",
|
title="Help",
|
||||||
color=0xBEBEFE
|
color=0x808080
|
||||||
)
|
)
|
||||||
|
embed.set_author(name="Help", icon_url="https://yes.nighty.works/raw/HP69uM.png")
|
||||||
|
|
||||||
available_categories = set()
|
available_categories = set()
|
||||||
for cog_name in self.bot.cogs:
|
for cog_name in self.bot.cogs:
|
||||||
@@ -99,7 +115,7 @@ class Help(commands.Cog, name="help"):
|
|||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
title="Error",
|
title="Error",
|
||||||
description=f"Category '{category}' not found. Use `/help` to see available categories.",
|
description=f"Category '{category}' not found. Use `/help` to see available categories.",
|
||||||
color=0xE02B2B
|
color=0x808080
|
||||||
)
|
)
|
||||||
if context.interaction:
|
if context.interaction:
|
||||||
await context.interaction.response.send_message(embed=embed, ephemeral=True)
|
await context.interaction.response.send_message(embed=embed, ephemeral=True)
|
||||||
@@ -111,7 +127,7 @@ class Help(commands.Cog, name="help"):
|
|||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
title="Error",
|
title="Error",
|
||||||
description="You don't have permission to view owner commands.",
|
description="You don't have permission to view owner commands.",
|
||||||
color=0xE02B2B
|
color=0x808080
|
||||||
)
|
)
|
||||||
if context.interaction:
|
if context.interaction:
|
||||||
await context.interaction.response.send_message(embed=embed, ephemeral=True)
|
await context.interaction.response.send_message(embed=embed, ephemeral=True)
|
||||||
@@ -133,7 +149,7 @@ class Help(commands.Cog, name="help"):
|
|||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
title="Error",
|
title="Error",
|
||||||
description=f"No commands found in category '{category}'.",
|
description=f"No commands found in category '{category}'.",
|
||||||
color=0xE02B2B
|
color=0x808080
|
||||||
)
|
)
|
||||||
if context.interaction:
|
if context.interaction:
|
||||||
await context.interaction.response.send_message(embed=embed, ephemeral=True)
|
await context.interaction.response.send_message(embed=embed, ephemeral=True)
|
||||||
@@ -142,21 +158,19 @@ class Help(commands.Cog, name="help"):
|
|||||||
return
|
return
|
||||||
|
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
title=f"Help » {category.capitalize()}",
|
title=f"/help » {category.lower()}",
|
||||||
color=0xBEBEFE
|
color=0x808080
|
||||||
)
|
)
|
||||||
|
embed.set_author(name="Help", icon_url="https://yes.nighty.works/raw/HP69uM.png")
|
||||||
data = []
|
data = []
|
||||||
for command_name, description in sorted(commands_in_category):
|
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)
|
help_text = "\n".join(data)
|
||||||
embed.add_field(
|
embed.add_field(
|
||||||
name="",
|
name="",
|
||||||
value=help_text,
|
value=help_text,
|
||||||
inline=False
|
inline=False
|
||||||
)
|
)
|
||||||
|
|
||||||
if context.interaction:
|
if context.interaction:
|
||||||
await context.interaction.response.send_message(embed=embed, ephemeral=True)
|
await context.interaction.response.send_message(embed=embed, ephemeral=True)
|
||||||
else:
|
else:
|
||||||
@@ -164,4 +178,4 @@ class Help(commands.Cog, name="help"):
|
|||||||
|
|
||||||
|
|
||||||
async def setup(bot) -> None:
|
async def setup(bot) -> None:
|
||||||
await bot.add_cog(Help(bot))
|
await bot.add_cog(Help(bot))
|
||||||
@@ -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
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from discord.ext.commands import Context
|
from discord.ext.commands import Context
|
||||||
|
|||||||
Reference in New Issue
Block a user