[英]how i get an user status and i give him a specific role, i tried but it doesn't work
async def on_message(message): if message.content.startswith("-test"): await message.channel.send("Checking for the Status:pencil:..") time.sleep(1) async def on_member_update(before, after): if str("discord.gg / discord") in member.activities[0].name(): print("Correct Status giving role to User") guild = client.get_guild(8516587165187561) role = discord.utils.get(guild.roles, id=9157981598717517571) await message.channel.send("roled")
i try to get an user status and if he have that status specified he get the role, i don't know why it doesn't work, i use discord.py我尝试获取用户状态,如果他指定了该状态,他将获得角色,我不知道为什么它不起作用,我使用 discord.py
There's no need to put on_member_update
in the code.无需在代码中
on_member_update
。 It wouldn't work anyway even if you do due to the fact it's an event function, not something you can call on.即使您这样做,它也不会起作用,因为这是一个事件 function,不是您可以调用的。
async def on_message(message):
if message.content.startswith("-test"):
await message.channel.send("Checking for the Status :pencil:..")
time.sleep(1)
if str("discord.gg / discord") in message.author.activities[0].name():
print("Correct Status giving role to User")
guild = client.get_guild(8516587165187561)
role = discord.utils.get(guild.roles, id=9157981598717517571)
await message.author.add_roles(role)
await message.channel.send("roled")
I've also added the await message.author.add_roles(role)
part because there wasn't any command that assign roles in your original code.我还添加了
await message.author.add_roles(role)
部分,因为在您的原始代码中没有任何命令分配角色。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.