def format_command_help(self, command, prefix): '''Formats command help.''' name = command.replace(' ', '_') cog = self.bot.cogs.get(name) if cog is not None: return self.format_cog_help(name, cog, prefix) cmd = self.bot.get_command(command) if cmd is not None: return discord.Embed(color=embeds.random_color(), title=f'`{prefix}{cmd.signature}`', description=cmd.help)
async def format_deck_and_send(self, ctx, profile): deck = profile.deck author = profile.name deck_image = await self.bot.loop.run_in_executor( None, self.get_deck_image, profile, author) em = discord.Embed(color=embeds.random_color()) if self.bot.psa_message: em.description = f'*{self.bot.psa_message}*' em.set_author(name=profile, icon_url=profile.clan_badge_url or 'https://i.imgur.com/Y3uXsgj.png') em.set_image(url='attachment://deck.png') em.set_footer(text='Statsy - Powered by cr-api.com') await ctx.send(file=discord.File(deck_image, 'deck.png'), embed=em) deck_image.close()
async def on_command_error(self, ctx, error): if isinstance(error, InvalidTag): await ctx.send(error.message) elif isinstance(error, commands.MissingRequiredArgument): prefix = (await self.get_prefix(ctx.message))[2] await ctx.send(embed=discord.Embed( color=embeds.random_color(), title=f'``Usage: {prefix}{ctx.command.signature}``', description=ctx.command.help)) else: error_message = 'Ignoring exception in command {}:\n'.format( ctx.command) error_message += ''.join( traceback.format_exception(type(error), error, error.__traceback__)) log_channel = self.get_channel(376622292106608640) em = discord.Embed(color=discord.Color.orange(), description=f"```\n{error_message}\n```", title=ctx.message.content) await log_channel.send(embed=em) print(error_message, file=sys.stderr)
def format_cog_help(self, name, cog, prefix): '''Formats the text for a cog help''' sigs = [] for cmd in self.bot.commands: if cmd.hidden: continue if cmd.instance is cog: sigs.append(len(cmd.qualified_name) + len(prefix)) if hasattr(cmd, 'all_commands'): for c in cmd.all_commands.values(): sigs.append(len('\u200b └─ ' + c.name) + 1) maxlen = max(sigs) fmt = '' for cmd in self.bot.commands: if cmd.instance is cog: if cmd.hidden: continue fmt += f'`{prefix+cmd.qualified_name:<{maxlen}} ' fmt += f'{cmd.short_doc:<{maxlen}}`\n' if hasattr(cmd, 'commands'): for c in cmd.commands: branch = '\u200b └─ ' + c.name fmt += f"`{branch:<{maxlen+1}} " fmt += f"{c.short_doc:<{maxlen}}`\n" em = discord.Embed(title=name.replace('_', ' ')) em.color = embeds.random_color() em.description = '*' + (self.bot.psa_message or inspect.getdoc(cog)) + '*' em.add_field(name='Commands', value=fmt) em.set_footer( text=f'Type {prefix}help command for more info on a command.') return em