成员更新时列出超出范围的索引 AuditLogAction discord.py

时间:2021-05-15 08:33:54

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

嗨,我想要代码记录器机器人,但我在会员更新事件上遇到了问题。 我想提及添加角色的人和获得角色的人。

所以我编码了这个:

@client.event
async def on_member_update(before , after):
    guild = after.guild
    logs = await guild.audit_logs(limit=1, action=discord.AuditLogAction.member_update).flatten()
    logs = logs[0]
    if len(before.roles) < len(after.roles):
        newrole = next(role for role in after.roles if role not in before.roles)
        await channel.send("Role Added By: "+logs.user.mention+"\nRole Added To: "+logs.target.mention+"\nRole: "+newrole)

但是我收到了这个错误:

in on_member_update
    logs = logs[0]
IndexError: list index out of range

我没有遇到其他事件的编码日志问题,例如:会员禁令和... 但在这种情况下,我遇到了这个问题。 我该怎么办?我没有找到任何解决方案。

0 个答案:

没有答案