Python 3.x 事件或命令中函数def的异步

Python 3.x 事件或命令中函数def的异步,python-3.x,discord,discord.py,Python 3.x,Discord,Discord.py,我想减少我在bot中的代码,我的第一次尝试以以下内容结束: <coroutine object logi_member_role_update.<locals>.logi_role_by at 0x000001D202E20A40> C:\Users\kacpe\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\client.py:343: RuntimeWarning: coroutine

我想减少我在bot中的代码,我的第一次尝试以以下内容结束:

<coroutine object logi_member_role_update.<locals>.logi_role_by at 0x000001D202E20A40>
C:\Users\kacpe\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\client.py:343: RuntimeWarning: coroutine 'logi_member_role_update.<locals>.logi_role_by' was never awaited
  await coro(*args, **kwargs)

我的问题是:遗漏了什么?

输出本身就足以说明问题-应该等待协同程序

member=wait logi\u member\u role\u update(之前)
此外,我不确定您为什么要通过函数包装
logi\u角色,您可以这样做

async def logi_成员更新(之前):
before.guild.audit\u日志中的作者异步(limit=1,最早的\u first=False,action=discord.AuditLogAction.member\u role\u update):
返回“{0.user.id}”。格式(作者)
#万一
成员=等待登录\成员\角色\更新(之前)

输出本身就足以说明问题-应该等待协同路由

member=wait logi\u member\u role\u update(之前)
此外,我不确定您为什么要通过
函数包装
logi\u角色,您可以这样做

async def logi_成员更新(之前):
before.guild.audit\u日志中的作者异步(limit=1,最早的\u first=False,action=discord.AuditLogAction.member\u role\u update):
返回“{0.user.id}”。格式(作者)
#万一
成员=等待登录\成员\角色\更新(之前)
def logi_member_role_update(before):
    async def logi_role_by(before):
        async for author in before.guild.audit_logs(limit = 1, oldest_first = False, action = discord.AuditLogAction.member_role_update):
            return '{0.user.id}'.format(author)
    return logi_role_by(before)

@client.event
async def on_member_update(before, after):
    e = discord.Embed(color = client.get_user(id_arnoldzika).color, timestamp = datetime.datetime.now(datetime.timezone.utc))
    e.set_thumbnail(url = before.avatar_url)
    if before.roles != after.roles:
        member = logi_member_role_update(before)
        print(member)