|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from typing import TYPE_CHECKING |
| 4 | + |
| 5 | +from discord import Color, Embed, Interaction, app_commands |
| 6 | +from discord.ext import commands |
| 7 | + |
| 8 | +if TYPE_CHECKING: |
| 9 | + from src.main import AeBot |
| 10 | + |
| 11 | + |
| 12 | +class HelpCog(commands.GroupCog, group_name="help"): |
| 13 | + def __init__(self, bot: AeBot): |
| 14 | + self.bot = bot |
| 15 | + |
| 16 | + @app_commands.command( |
| 17 | + name="help", |
| 18 | + description=( |
| 19 | + "Affiche la liste des commandes avec" |
| 20 | + " leurs sous-commandes et leurs description" |
| 21 | + ), |
| 22 | + ) |
| 23 | + async def help(self, interaction: Interaction): |
| 24 | + embed = Embed(title="Aide du bot", color=Color.blue()) |
| 25 | + |
| 26 | + for command in self.bot.tree.get_commands(): |
| 27 | + if isinstance(command, app_commands.Group) and command.commands: |
| 28 | + subcommands = "\n".join( |
| 29 | + f" /{command.name} {sub.name} - {sub.description}" |
| 30 | + for sub in command.commands |
| 31 | + ) |
| 32 | + embed.add_field( |
| 33 | + name=f"/{command.name} (groupe)", value=subcommands, inline=False |
| 34 | + ) |
| 35 | + else: |
| 36 | + embed.add_field( |
| 37 | + name=f"/{command.name}", |
| 38 | + value=command.description or "Pas de description.", |
| 39 | + inline=False, |
| 40 | + ) |
| 41 | + |
| 42 | + await interaction.response.send_message(embed=embed, ephemeral=True) |
0 commit comments