Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

python - discord.py how to organize help command

I got getting all commands working, but I cant figure out how I can sort them like:

Images:
avatar <user> > get someones avatar
etc.
Text:
clap <text> > generate text with clapping emojis
etc.

heres what i have right now:

@bot.command(usage="test [command]", description="get help")
async def test2(ctx, args=None):
dude = ''
if args is None:
    for i,x in enumerate(bot.commands):
        dude += (f'{PREFIX}{x.usage} ? {x.description}
')
    await ctx.send(f'```{dude}```')

I tried making them as groups but then realized i would have to use them with image avatar @peter


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

1 Answer

0 votes
by (71.8m points)

I ended up getting around the problems by using brief='x_command' as an thing to recognize the commands category

@bot.command(usage="test [command]", description="get help")
async def test2(ctx, args=None):
dude = ''
if args is None:
    for i,x in enumerate(bot.commands):
        if x.brief == 'image_command':
            dude += (f'{PREFIX}{x.usage} ? {x.description}
')
    await ctx.send(f'```{dude}```')

so the commands look like this

@bot.command(brief='image_command',usage="avatar <user>", description="send users avatar to chat")
async def avatar(icy, user:discord.User):
await icy.message.delete()
await icy.send(user.avatar_url)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...