如何使漫游器发送多个命令以得到1个命令

时间:2018-06-22 10:02:11

标签: python python-3.x discord discord.py

如何使漫游器通过一个命令回复多个命令。标签之类的示例。

browsers = ['chrome', 'mozilla', 'ie', 'safari']

@bot.command(pass_context=True)
async def chrome(ctx):
    msg = "about Chrome. {0.author.mention}".format(ctx.message)
    await bot.say(msg)

@bot.command(pass_context=True)
async def mozilla(ctx):
    msg = "about Mozilla. {0.author.mention}".format(ctx.message)
    await bot.say(msg)

@bot.command(pass_context=True)
async def safari(ctx):
    msg = "about Safari. {0.author.mention}".format(ctx.message)
    await bot.say(msg)

因此,最后,如果用户键入?browsers命令,它应该发送browsers列表中的所有命令答复。如果键入?chrome?mozilla?safari

,它也应该单独工作

1 个答案:

答案 0 :(得分:2)

这是我能找到的唯一方法,但这有点尴尬。

@bot.command(pass_context=True)
async def chrome(ctx):
    msg = "about Chrome. {0.author.mention}".format(ctx.message)
    await bot.say(msg)

@bot.command(pass_context=True)
async def mozilla(ctx):
    msg = "about Mozilla. {0.author.mention}".format(ctx.message)
    await bot.say(msg)

@bot.command(pass_context=True)
async def safari(ctx):
    msg = "about Safari. {0.author.mention}".format(ctx.message)
    await bot.say(msg)

@bot.group(pass_context=True)
async def browsers(ctx):
    if ctx.invoked_subcommand is None:
        for command in browsers.walk_commands():
            await command.invoke(ctx)

browsers.add_command(chrome)
browsers.add_command(mozilla)
browsers.add_command(safari)

我非常怀疑,这是一种更干净的方法,您可以使用@browsers.command()定义命令,然后还可以直接调用它们,但我找不到它。

相关问题