Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
249 views
in Technique[技术] by (71.8m points)

Discord Python Subcommands aren't working?

I've tried many possible solutions to these subcommands but I can't find the issue.

@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='
Information', value='``userinfo``, ``avatar``, ``rules``', inline=False)
        embed.add_field(name='
Moderation',
                        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

Is there any fix out there to this? I couldn't find one myself. ';help' is the normal command to get all the commands. Subcommands would be ';help userinfo', ';help rules', etc. I've asked around in the discord.py discord server, and I've also tried going the the official Python discord server to get help. But nothing seems to work. Any fixes? Any help would be awesome :)

question from:https://stackoverflow.com/questions/65870440/discord-python-subcommands-arent-working

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use commands.HelpCommand or commands.MinimalHelpCommand

for example:

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

Note: The example I used was taken from the discord.py discord server.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...