简体   繁体   English

我如何获得用户状态并给他一个特定的角色,我试过但它不起作用

[英]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.

相关问题 如何检查用户是否没有赋予角色? - How can I check to see if a user doesn't gave a role? 如何获得消息中提到的 Discord 成员并授予他角色? - How do I get Discord member, mentioned in the message and grant him a role? 如何让我的 Discord 机器人给用户一个角色? - How can I make my Discord bot give a user a role? 我怎样才能给 discord 用户一个特定的角色限制? - How can I give discord users with a specific role limitations? 当用户加入服务器时,我如何给用户一个角色? - How i can give a role to user when its join the server? 如何让我的 Discord Bot 使用他们的用户 ID 向另一个用户发送私人消息,我尝试了以下操作,但没有成功 - How Do I get my Discord Bot to Send a private message to another user using their user ID,I tried the following but it did not work 如何通过用户 ID 赋予用户角色? 我想在命令中输入用户 ID(参数) - How to give user role by user id? I want to type user id in command (arguments) 如何获得 discord 消息的作者,然后私信他? - How do I get the author of a discord message and then DM him? 如何为成员提供具有角色 ID 的角色? - How can I give member a role with role id? 我可以给拥有最多硬币的用户一个自动角色吗? - Can I give an automatic role to the user with most coins?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM