Skip to content

Commit

Permalink
optimize help command: dynamic title, dynamic prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
RealMuffinTime committed Sep 14, 2022
1 parent 582fe9c commit 3bb6234
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
16 changes: 9 additions & 7 deletions cogs/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ async def help_command(self, ctx, cog='all'):
return
color = ctx.channel.guild.me.color.value

help_embed = discord.Embed(
title=f'Help page of {self.bot.user}',
color=color
)
help_embed = discord.Embed(color=color)

help_embed.set_footer(
text=f'Requested by {ctx.message.author.name}',
icon_url=ctx.message.author.avatar
Expand All @@ -44,6 +42,9 @@ async def help_command(self, ctx, cog='all'):
# If cog is not specified by the user, we list all cogs and commands

if cog == 'all':

help_embed.title = f"Help page of {self.bot.user}"

for cog in cogs:
# Get a list of all commands under each cog

Expand Down Expand Up @@ -74,7 +75,9 @@ async def help_command(self, ctx, cog='all'):
if cog.lower() in lower_cogs:

# Get a list of all commands in the specified cog
commands_list = self.bot.get_cog(cogs[lower_cogs.index(cog.lower())]).get_commands()
cog_object = self.bot.get_cog(cogs[lower_cogs.index(cog.lower())])
help_embed.title = f"Help page for {cog.title()}"
commands_list = cog_object.get_commands()
help_text = ''

# Add details of each command to the help text
Expand All @@ -91,8 +94,7 @@ async def help_command(self, ctx, cog='all'):
help_text += f"Aliases: `{', '.join(command.aliases)}`\n"

# Finally the format
help_text += f'Format: `@{self.bot.user.name}#{self.bot.user.discriminator}' \
f' {command.name} {command.usage if command.usage is not None else ""}`\n\n'
help_text += f'Format: `{ctx.prefix}{command.name} {command.usage if command.usage is not None else ""}`\n\n'

help_embed.description = help_text
else:
Expand Down
1 change: 1 addition & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# - managed channel adds new channel under last current existing
# - managed channel checks for channels after start of bot
# Changes
# - optimized help command: dynamic title, dynamic prefix
# - moved to discord.py v2.x
# - multiple reworks of afk management
# - (error) logging optimization
Expand Down

0 comments on commit 3bb6234

Please sign in to comment.