【问题标题】:how i get an user status and i give him a specific role, i tried but it doesn't work我如何获得用户状态并给他一个特定的角色,我试过但它不起作用
【发布时间】:2021-08-11 13:32:57
【问题描述】:

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")

我尝试获取用户状态,如果他指定了该状态,他将获得角色,我不知道为什么它不起作用,我使用 discord.py

【问题讨论】:

  • 有人可以帮忙吗

标签: discord


【解决方案1】:

无需在代码中输入on_member_update。即使你这样做,它也不会工作,因为它是一个事件函数,而不是你可以调用的东西。

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")

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-07
    • 1970-01-01
    • 2021-08-04
    • 2020-11-17
    • 2020-08-08
    • 2010-11-25
    • 1970-01-01
    相关资源
    最近更新 更多