【问题标题】:How to call async function for discord bot如何为不和谐机器人调用异步函数
【发布时间】:2023-03-31 09:58:02
【问题描述】:

我有一个(工作的)命令,它从我的硬盘读取一个文件并通过我的不和谐机器人播放它:

@client.command(pass_context=True)
async def fp(ctx, file):

其中 file 是列表中项目的名称。由于某些命令的使用频率更高,我想知道如何在另一个中引用此函数以获取更常见的命令。大致如下:

@client.command(pass_context=True)
async def crab(ctx):
    client.commands.fp(ctx, "crab")

但经过大量修补后,我无法使其正常工作。任何帮助表示赞赏!

【问题讨论】:

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


【解决方案1】:

您可以像 Patrick 提到的那样使用 .invoke 函数

@bot.command()
async def crab(ctx):
    await fp.invoke(ctx, "crab")

或使用.callback 函数

@bot.command()
async def fp(ctx, file):
   // do something.

bot.command(name="crab")(fp.callback)

【讨论】:

    猜你喜欢
    • 2018-11-10
    • 1970-01-01
    • 1970-01-01
    • 2020-07-22
    • 2018-03-20
    • 1970-01-01
    • 2021-04-26
    • 1970-01-01
    • 2021-07-13
    相关资源
    最近更新 更多