如何让机器人发送 1 个通信的多个回复



如何让机器人发送多个命令回复一个命令。

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,它应该单独工作

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

@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()定义命令,然后还可以直接调用它们,但我找不到它。

最新更新