Discord 我如何获得用户状态并给他一个特定的角色,我尝试过,但没有';行不通

Discord 我如何获得用户状态并给他一个特定的角色,我尝试过,但没有';行不通,discord,Discord,async def on_消息(消息): 如果message.content.startswith(“-test”): wait message.channel.send(“检查状态:pencil:…”) 时间。睡眠(1) 成员更新时的异步定义(之前、之后): 如果在member.activities[0].name()中有str(“discord.gg/discord”): 打印(“将角色赋予用户的正确状态”) 帮会=客户。获取帮会(8516587165187561) role=discord

async def on_消息(消息):
如果message.content.startswith(“-test”):
wait message.channel.send(“检查状态:pencil:…”)
时间。睡眠(1)
成员更新时的异步定义(之前、之后):
如果在member.activities[0].name()中有str(“discord.gg/discord”):
打印(“将角色赋予用户的正确状态”)
帮会=客户。获取帮会(8516587165187561)
role=discord.utils.get(guild.roles,id=9157981598717571)

等待消息。频道。发送(“roled”)
无需在代码中的成员更新上添加
。因为它是一个事件函数,而不是您可以调用的东西,所以即使您这样做,它也不会工作

async def on_消息(消息):
如果message.content.startswith(“-test”):
wait message.channel.send(“检查状态:pencil:…”)
时间。睡眠(1)
如果message.author.activities[0].name()中有str(“discord.gg/discord”):
打印(“将角色赋予用户的正确状态”)
帮会=客户。获取帮会(8516587165187561)
role=discord.utils.get(guild.roles,id=9157981598717571)
等待消息。作者。添加角色(角色)
等待消息。频道。发送(“roled”)

我还添加了
wait message.author.add_roles(role)
部分,因为原始代码中没有任何分配角色的命令。

有人能帮忙吗