gpt4 book ai didi

discord.py - 让 Discord.py(重写)机器人检测事件 on_member_update 上的角色更改

转载 作者:行者123 更新时间:2023-12-02 02:47:46 24 4
gpt4 key购买 nike

我试图做到这一点,以便机器人会祝贺任何从成员(member)晋升为受人​​尊敬的人(它不会自动晋升;管理员/所有者会)。但是,对于以下代码,每次我将某人从 Member 提升为 Respected 时,它都不会检测到提升。

@client.event
async def on_member_update(before, after):
if [i.id for i in before.roles].count(650019191092674569) == 1:
if [i.id for i in after.roles].count('658164877172408320') == 1:
channel = client.get_channel(649833392854007808)
print(f"""Recognized that {after.name} has been promoted from Member to Respected""")
await channel.send(f"""Congratulations {after.mention} for getting promoted to Respected!""")

我也试过这段代码,虽然机器人也没有检测到促销。

@client.event
async def on_member_update(before, after):
if before.roles.count(650019191092674569) == 1:
if after.roles.count('658164877172408320') == 1:
channel = client.get_channel(649833392854007808)
print(f"""Recognized that {after.name} has been promoted from Member to Respected""")
await channel.send(f"""Congratulations {after.mention} for getting promoted to Respected!""")

有什么我忘记配置的东西需要它来检测角色变化吗?

最佳答案

我希望这里有一些代码可以帮助您创建一些可行的解决方案。每当有人获得受人尊敬的角色时,此代码都会发送一条消息

@client.event
async def on_member_update(before, after):
if len(before.roles) < len(after.roles):
# The user has gained a new role, so lets find out which one
newRole = next(role for role in after.roles if role not in before.roles)

if newRole.name == "Respected":
# This uses the name but you could always use newRole.id == Roleid here
# Now, simply put the code you want to run whenever someone gets the "Respected" role here

希望这对您有所帮助!

关于discord.py - 让 Discord.py(重写)机器人检测事件 on_member_update 上的角色更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62494041/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com