首页 > 解决方案 > 如何在命令中激活命令 (discord.py)

问题描述

我想做的是让机器人在“帮助”命令列表下对命令做出响应

 @bot.command(pass_context = True)
    async def help(ctx):
        a_embed1 = discord.Embed(title="Vibe's Command List")
        a_embed1.add_field(name=':smile: Fun', value="`vb help fun`", inline=True)
        await ctx.send(embed=a_embed1)

就像当我输入“ prefix_here help Economy”时,将发送经济嵌入列表而不是帮助嵌入列表。任何帮助将非常感激!

标签: pythonpython-3.xdiscorddiscord.py

解决方案


添加一个参数并将其默认为 None 然后检查它是否不是 None 然后发送通用帮助命令 否则使用 if-elifs 检查它等于什么并发送它的帮助

@bot.command()
async def help(ctx, c=None):
    if not c: # normal help command
        a_embed1 = discord.Embed(title="Vibe's Command List")
        a_embed1.add_field(name=':smile: Fun', value="`vb help fun`", inline=True)
        await ctx.send(embed=a_embed1)
    elif c.lower() == "economy":
        # define embed and send
    # multiple elifs for other commands

推荐阅读