Discord Python 子命令不起作用?

时间:2021-01-24 12:18:32

标签: python discord discord.py python-3.6 discord.py-rewrite

对于这些子命令,我已经尝试了许多可能的解决方案,但我找不到问题所在。

@client.command(aliases=['commands', 'Commands', 'Help'])
async def help(ctx, command=None):
    if command == None:
        author = ctx.message.author
        embed = discord.Embed(colour=discord.Colour.magenta())
        embed.set_author(name='Help Command')
        embed.add_field(name='Here are all the commands!',
                        value='If you want to know how to use a command, do ``;help <command name>`` *--coming soon--*',
                        inline=False)
        embed.add_field(name='Miscellaneous',
                        value='``8ball``, ``flip``, ``userinfo``, ``drip``, ``annoy``, ``hug``, ``slap``, ``cry`` ``pat``, ``punch``, ``invite``',
                        inline=False)
        embed.add_field(name='\nInformation', value='``userinfo``, ``avatar``, ``rules``', inline=False)
        embed.add_field(name='\nModeration',
                        value='``kick``, ``ban``, ``unban``, ``mute``, ``unmute``, ``report``, ``clear``', inline=False)
        await ctx.author.send(embed=embed)
        await ctx.send(f'***✅ {author.mention} Check  your DMs!***')
    if command == '8ball':
        embed = discord.Embed(colour=discord.Colour.magenta())
        embed.add_field(name='8ball command', value='A random yes/no answer. ``;8ball <question>``')
        embed.thumbnail(url='https://cdn.discordapp.com/attachments/801233629954048040/802533814282879026/e39-min.png')
        embed.set_footer(icon_url=ctx.author.avatar_url, text=f'Requested by {ctx.author.name}')
        await ctx.author.send(embed=embed)
        return
    if command == 'flip':
        embed = discord.Embed(colour=discord.Colour.magenta())
        embed.add_field(name='Flip command', value='Flips a coin. ``;flip <question>``')
        embed.thumbnail(url='https://cdn.discordapp.com/attachments/801233629954048040/802533814282879026/e39-min.png')
        embed.set_footer(icon_url=ctx.author.avatar_url, text=f'Requested by {ctx.author.name}')
        await ctx.author.send(embed=embed)
        return
    if command == 'userinfo':
        embed = discord.Embed(colour=discord.Colour.magenta())
        embed.add_field(name='Userinfo command', value='Displays user information. ``;userinfo``')
        embed.thumbnail(url='https://cdn.discordapp.com/attachments/801233629954048040/802533814282879026/e39-min.png')
        embed.set_footer(icon_url=ctx.author.avatar_url, text=f'Requested by {ctx.author.name}')
        await ctx.author.send(embed=embed)
        return
    if command == 'drip':
        embed = discord.Embed(colour=discord.Colour.magenta())
        embed.add_field(name='Drip command', value='Shows you the real drip. ``;drip``')
        embed.thumbnail(url='https://cdn.discordapp.com/attachments/801233629954048040/802533814282879026/e39-min.png')
        embed.set_footer(icon_url=ctx.author.avatar_url, text=f'Requested by {ctx.author.name}')
        await ctx.author.send(embed=embed)
        return
    if command == 'annoy':
        embed = discord.Embed(colour=discord.Colour.magenta())
        embed.add_field(name='Annoy command', value='Pings a user 10 times. ``;annoy user``')
        embed.thumbnail(url='https://cdn.discordapp.com/attachments/801233629954048040/802533814282879026/e39-min.png')
        embed.set_footer(icon_url=ctx.author.avatar_url, text=f'Requested by {ctx.author.name}')
        await ctx.author.send(embed=embed)
        return
    if command == 'hug':
        embed = discord.Embed(colour=discord.Colour.magenta())
        embed.add_field(name='Hug command', value='Hugs the user. ``;hug <user>``')
        embed.thumbnail(url='https://cdn.discordapp.com/attachments/801233629954048040/802533814282879026/e39-min.png')
        embed.set_footer(icon_url=ctx.author.avatar_url, text=f'Requested by {ctx.author.name}')
        await ctx.author.send(embed=embed)
        return
    if command == 'slap':
        embed = discord.Embed(colour=discord.Colour.magenta())
        embed.add_field(name='Slap command', value='Slaps the user. ``;slap <user>``')
        embed.thumbnail(url='https://cdn.discordapp.com/attachments/801233629954048040/802533814282879026/e39-min.png')
        embed.set_footer(icon_url=ctx.author.avatar_url, text=f'Requested by {ctx.author.name}')
        await ctx.author.send(embed=embed)
        return
    if command == 'cry':
        embed = discord.Embed(colour=discord.Colour.magenta())
        embed.add_field(name='Cry command', value='You cry. ``;cry``')
        embed.thumbnail(url='https://cdn.discordapp.com/attachments/801233629954048040/802533814282879026/e39-min.png')
        embed.set_footer(icon_url=ctx.author.avatar_url, text=f'Requested by {ctx.author.name}')
        await ctx.author.send(embed=embed)
        return
    if command == 'pat':
        embed = discord.Embed(colour=discord.Colour.magenta())
        embed.add_field(name='Pat command', value='Pats user``;pat <user>``')
        embed.thumbnail(url='https://cdn.discordapp.com/attachments/801233629954048040/802533814282879026/e39-min.png')
        embed.set_footer(icon_url=ctx.author.avatar_url, text=f'Requested by {ctx.author.name}')
        await ctx.author.send(embed=embed)
        return
    if command == 'punch':
        embed = discord.Embed(colour=discord.Colour.magenta())
        embed.add_field(name='Punch command', value='Punches user. ``;punch <user>``')
        embed.thumbnail(url='https://cdn.discordapp.com/attachments/801233629954048040/802533814282879026/e39-min.png')
        embed.set_footer(icon_url=ctx.author.avatar_url, text=f'Requested by {ctx.author.name}')
        await ctx.author.send(embed=embed)
        return
    if command == 'invite':
        embed = discord.Embed(colour=discord.Colour.magenta())
        embed.add_field(name='Invite command', value='Gives you the permanent invite link. ``;invite``')
        embed.thumbnail(url='https://cdn.discordapp.com/attachments/801233629954048040/802533814282879026/e39-min.png')
        embed.set_footer(icon_url=ctx.author.avatar_url, text=f'Requested by {ctx.author.name}')
        await ctx.author.send(embed=embed)
        return
    if command == 'userinfo':
        embed = discord.Embed(colour=discord.Colour.magenta())
        embed.add_field(name='Userinfo command', value='Shows information about user``;userinfo <user>``')
        embed.thumbnail(url='https://cdn.discordapp.com/attachments/801233629954048040/802533814282879026/e39-min.png')
        embed.set_footer(icon_url=ctx.author.avatar_url, text=f'Requested by {ctx.author.name}')
        await ctx.author.send(embed=embed)
        return
    if command == 'avatar':
        embed = discord.Embed(colour=discord.Colour.magenta())
        embed.add_field(name='Avatar command', value='Shows users avatar. ``;avatar <user>``')
        embed.thumbnail(url='https://cdn.discordapp.com/attachments/801233629954048040/802533814282879026/e39-min.png')
        embed.set_footer(icon_url=ctx.author.avatar_url, text=f'Requested by {ctx.author.name}')
        await ctx.author.send(embed=embed)
        return
    if command == 'rules':
        embed = discord.Embed(colour=discord.Colour.magenta())
        embed.add_field(name='Rules command', value='Shows you server rules. ``;rules``')
        embed.thumbnail(url='https://cdn.discordapp.com/attachments/801233629954048040/802533814282879026/e39-min.png')
        embed.set_footer(icon_url=ctx.author.avatar_url, text=f'Requested by {ctx.author.name}')
        await ctx.author.send(embed=embed)
        return
    if command == 'kick':
        embed = discord.Embed(colour=discord.Colour.magenta())
        embed.add_field(name='Kick command', value='Kicks mentioned user. ``;kick <user>``')
        embed.thumbnail(url='https://cdn.discordapp.com/attachments/801233629954048040/802533814282879026/e39-min.png')
        embed.set_footer(icon_url=ctx.author.avatar_url, text=f'Requested by {ctx.author.name}')
        await ctx.author.send(embed=embed)
        return
    if command == 'ban':
        embed = discord.Embed(colour=discord.Colour.magenta())
        embed.add_field(name='Ban command', value='Bans mentioned user. ``;ban <user>``')
        embed.thumbnail(url='https://cdn.discordapp.com/attachments/801233629954048040/802533814282879026/e39-min.png')
        embed.set_footer(icon_url=ctx.author.avatar_url, text=f'Requested by {ctx.author.name}')
        await ctx.author.send(embed=embed)
        return
    if command == 'unban':
        embed = discord.Embed(colour=discord.Colour.magenta())
        embed.add_field(name='Unban command', value='Unbans user. ``;unban <user tag(name#0001)>``')
        embed.thumbnail(url='https://cdn.discordapp.com/attachments/801233629954048040/802533814282879026/e39-min.png')
        embed.set_footer(icon_url=ctx.author.avatar_url, text=f'Requested by {ctx.author.name}')
        await ctx.author.send(embed=embed)
        return
    if command == 'mute':
        embed = discord.Embed(colour=discord.Colour.magenta())
        embed.add_field(name='Mute command', value='Mutes mentioned user. ``;mute <user>``')
        embed.thumbnail(url='https://cdn.discordapp.com/attachments/801233629954048040/802533814282879026/e39-min.png')
        embed.set_footer(icon_url=ctx.author.avatar_url, text=f'Requested by {ctx.author.name}')
        await ctx.author.send(embed=embed)
        return
    if command == 'unmute':
        embed = discord.Embed(colour=discord.Colour.magenta())
        embed.add_field(name='Unmute command', value='Unmutes mentioned user. ``;unmute <user>``')
        embed.thumbnail(url='https://cdn.discordapp.com/attachments/801233629954048040/802533814282879026/e39-min.png')
        embed.set_footer(icon_url=ctx.author.avatar_url, text=f'Requested by {ctx.author.name}')
        await ctx.author.send(embed=embed)
        return
    if command == 'clear':
        embed = discord.Embed(colour=discord.Colour.magenta())
        embed.add_field(name='Clear command', value='Clears recent messages. ``;clear <amount>``')
        embed.thumbnail(url='https://cdn.discordapp.com/attachments/801233629954048040/802533814282879026/e39-min.png')
        embed.set_footer(icon_url=ctx.author.avatar_url, text=f'Requested by {ctx.author.name}')
        await ctx.author.send(embed=embed)
        return
    if command == 'report':
        embed = discord.Embed(colour=discord.Colour.magenta())
        embed.add_field(name='Report command', value='Reports user to staff team. ``;report <grade (mild / severe / urgent)> <user> <reason>``')
        embed.thumbnail(url='https://cdn.discordapp.com/attachments/801233629954048040/802533814282879026/e39-min.png')
        embed.set_footer(icon_url=ctx.author.avatar_url, text=f'Requested by {ctx.author.name}')
        await ctx.author.send(embed=embed)
        return

有什么办法可以解决这个问题吗?我自己找不到。 ';help' 是获取所有命令的普通命令。子命令将是 ';help userinfo'、';help rules' 等。我在 discord.py discord 服务器中询问过,我也尝试去官方 Python discord 服务器获取帮助。但似乎没有任何效果。任何修复? 任何帮助都会很棒:)

1 个答案:

答案 0 :(得分:0)

您可以使用 commands.HelpCommand 或 commands.MinimalHelpCommand

例如:

class MyHelpCommand(commands.MinimalHelpCommand):
    def get_command_signature(self, command):
        return '{0.clean_prefix}{1.qualified_name} {1.signature}'.format(self, command)

class MyCog(commands.Cog):
    def __init__(self, bot):
        self._original_help_command = bot.help_command
        bot.help_command = MyHelpCommand()
        bot.help_command.cog = self

    def cog_unload(self):
        self.bot.help_command = self._original_help_command

Help command docs

RoboDanny's Help command

注意: 我使用的示例取自 discord.py discord 服务器。