ajout help slash command + cog desc in regular help
This commit is contained in:
parent
3233b7b709
commit
65325f8b5d
1 changed files with 24 additions and 12 deletions
|
@ -1,5 +1,6 @@
|
||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
from discord_slash import cog_ext
|
||||||
|
|
||||||
def setup(client):
|
def setup(client):
|
||||||
client.add_cog(Help(client))
|
client.add_cog(Help(client))
|
||||||
|
@ -14,9 +15,14 @@ class Help(commands.Cog):
|
||||||
@commands.command(name='help')
|
@commands.command(name='help')
|
||||||
async def _help(self, ctx, *cog):
|
async def _help(self, ctx, *cog):
|
||||||
"""Affiche toutes les commandes du bot.\n ➡ Syntaxe: {PREFIX}help [catégorie]"""
|
"""Affiche toutes les commandes du bot.\n ➡ Syntaxe: {PREFIX}help [catégorie]"""
|
||||||
if not cog:
|
fromSlash = False
|
||||||
"""Liste des Cog"""
|
if len(cog) > 0:
|
||||||
halp=discord.Embed(title = 'Liste des catégories et commandes sans catégorie',
|
if cog[-1] == True:
|
||||||
|
fromSlash = cog[-1]
|
||||||
|
cog = cog[:-1]
|
||||||
|
|
||||||
|
if not cog: # Liste des Cog
|
||||||
|
halp = discord.Embed(title = 'Liste des catégories et commandes sans catégorie',
|
||||||
description = f'Utilisez `{ctx.prefix}help [catégorie]` pour en savoir plus sur elles et leur commande.',
|
description = f'Utilisez `{ctx.prefix}help [catégorie]` pour en savoir plus sur elles et leur commande.',
|
||||||
color = discord.Colour.random())
|
color = discord.Colour.random())
|
||||||
for name_cog in self.client.cogs:
|
for name_cog in self.client.cogs:
|
||||||
|
@ -27,7 +33,7 @@ class Help(commands.Cog):
|
||||||
liste_cmds += f", `{ctx.prefix}{cmds.name}`"
|
liste_cmds += f", `{ctx.prefix}{cmds.name}`"
|
||||||
nb_cmds += 1
|
nb_cmds += 1
|
||||||
if name_cog != "Help" and nb_cmds > 0:
|
if name_cog != "Help" and nb_cmds > 0:
|
||||||
halp.add_field(name = f'**{name_cog} — {nb_cmds}**', value = liste_cmds[2:], inline = False)
|
halp.add_field(name = f'**{name_cog} ({nb_cmds}) — {self.client.cogs[name_cog].__doc__}**', value = liste_cmds[2:], inline = False)
|
||||||
cmds_desc = ''
|
cmds_desc = ''
|
||||||
for y in self.client.walk_commands():
|
for y in self.client.walk_commands():
|
||||||
if not y.cog_name and not y.hidden:
|
if not y.cog_name and not y.hidden:
|
||||||
|
@ -35,15 +41,14 @@ class Help(commands.Cog):
|
||||||
|
|
||||||
if len(cmds_desc) > 1:
|
if len(cmds_desc) > 1:
|
||||||
halp.add_field(name = 'Commandes sans catégorie', value = cmds_desc[0:len(cmds_desc)-1], inline = False)
|
halp.add_field(name = 'Commandes sans catégorie', value = cmds_desc[0:len(cmds_desc)-1], inline = False)
|
||||||
await ctx.message.add_reaction(emoji = '✅')
|
if fromSlash != True:
|
||||||
|
await ctx.message.add_reaction(emoji = '✅')
|
||||||
await ctx.send(embed = halp)
|
await ctx.send(embed = halp)
|
||||||
else:
|
else: # Avertissement si il y a trop d'arguments dans la variable cog
|
||||||
"""Avertissement si il y a trop d'arguments dans la variable cog"""
|
|
||||||
if len(cog) > 1:
|
if len(cog) > 1:
|
||||||
halp = discord.Embed(title = 'Erreur !', description = "Tu as renseigné trop d'arguments !", color = 0xC41B1B)
|
halp = discord.Embed(title = 'Erreur !', description = "Tu as renseigné trop d'arguments !", color = 0xC41B1B)
|
||||||
await ctx.send(embed = halp)
|
await ctx.send(embed = halp)
|
||||||
else:
|
else: # Liste des commandes avec cogs.
|
||||||
"""Liste des commandes avec cogs."""
|
|
||||||
cog = [item.capitalize() for item in cog]
|
cog = [item.capitalize() for item in cog]
|
||||||
found = False
|
found = False
|
||||||
for x in self.client.cogs:
|
for x in self.client.cogs:
|
||||||
|
@ -57,10 +62,17 @@ class Help(commands.Cog):
|
||||||
backslash = '\n'
|
backslash = '\n'
|
||||||
halp.add_field(name = f"`{ctx.prefix}{c.name}` - {str(c.help).split(backslash)[0]}", value = f"{''.join(cmds_help)}\u200b", inline = False)
|
halp.add_field(name = f"`{ctx.prefix}{c.name}` - {str(c.help).split(backslash)[0]}", value = f"{''.join(cmds_help)}\u200b", inline = False)
|
||||||
found = True
|
found = True
|
||||||
if not found:
|
if not found: # Rappel si le cog n'existe pas.
|
||||||
"""Rappel si le cog n'existe pas."""
|
|
||||||
await ctx.message.add_reaction(emoji = '❌')
|
await ctx.message.add_reaction(emoji = '❌')
|
||||||
halp = discord.Embed(title = 'Erreur !', description = f"Qu'est ce que {cog[0]} ?", color = 0xC41B1B)
|
halp = discord.Embed(title = 'Erreur !', description = f"Qu'est ce que {cog[0]} ?", color = 0xC41B1B)
|
||||||
else:
|
else:
|
||||||
await ctx.message.add_reaction(emoji = '✅')
|
if fromSlash != True:
|
||||||
|
await ctx.message.add_reaction(emoji = '✅')
|
||||||
await ctx.send('', embed = halp)
|
await ctx.send('', embed = halp)
|
||||||
|
@cog_ext.cog_slash(name="help", description = "Envois un meme de reddit.")
|
||||||
|
async def __help(self, ctx, cog = None):
|
||||||
|
ctx.prefix = "/"
|
||||||
|
if cog == None:
|
||||||
|
return await self._help(ctx, True)
|
||||||
|
else:
|
||||||
|
return await self._help(ctx, cog, True)
|
||||||
|
|
Reference in a new issue