This repository has been archived on 2022-03-31. You can view files and clone it, but cannot push or open issues or pull requests.
bot-licence/cogs/help.py
2020-10-14 03:23:14 +02:00

63 lines
No EOL
3 KiB
Python
Executable file
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import discord
from discord.ext import commands
from random import randint
# il y a deja une commande help de base mais celle ci est + jolie
class Help(commands.Cog):
"""Listes des commandes et/ou catégories."""
def __init__(self, bot):
self.bot = bot
@commands.command()
async def help(self, ctx, *cog):
"""Affiche toutes les commandes du bot.\n ➡ Syntaxe: .help [catégorie]"""
if not cog:
"""Liste des Cog"""
halp=discord.Embed(title = 'Liste des catégories et commandes non catégorisées',
description = 'Utilisez `.help *Catégorie*` pour en savoir plus sur eux !',
color = randint(0, 0xFFFFFF))
# liste des cogs
cogs_desc = ''
for x in self.bot.cogs:
cogs_desc += (f'{x} - {self.bot.cogs[x].__doc__}\n')
halp.add_field(name = 'Catégories', value = cogs_desc[0:len(cogs_desc)-1], inline = False)
# liste des commandes dans main.py
cmds_desc = ''
for y in self.bot.walk_commands():
if not y.cog_name and not y.hidden:
cmds_desc += (f'.{y.name} - {y.help}\n ')
if len(cmds_desc) > 1:
halp.add_field(name = 'Commandes sans catégories', value = cmds_desc[0:len(cmds_desc)-1], inline = False)
await ctx.message.add_reaction(emoji = '')
await ctx.send(embed = halp)
else:
"""Avertissement si il y a trop d'arguments dans la variable cog"""
if len(cog) > 1:
halp = discord.Embed(title = 'Erreur !', description = "Tu as renseigné trop d'arguments !", color = 0xC41B1B)
await ctx.send(embed = halp)
else:
"""Liste des commandes avec cogs."""
cog = [item.capitalize() for item in cog]
found = False
for x in self.bot.cogs:
for y in cog:
if x == y:
halp = discord.Embed(title = f'{cog[0]} - Liste des commandes', description = self.bot.cogs[cog[0]].__doc__, color = randint(0, 0xFFFFFF))
for c in self.bot.get_cog(y).get_commands():
if not c.hidden:
halp.add_field(name = f".{c.name}", value = f"{c.help}\n ", inline = False)
found = True
if not found:
"""Rappel si le cog n'existe pas."""
await ctx.message.add_reaction(emoji = '')
halp = discord.Embed(title = 'Erreur !', description = f"Qu'est ce que {cog[0]} ?", color = 0xC41B1B)
else:
await ctx.message.add_reaction(emoji = '')
await ctx.send('', embed = halp)
def setup(bot):
bot.add_cog(Help(bot))