识别某人正在玩的游戏而没有聊天(Discord Bot Python)

时间:2020-05-17 17:41:31

标签: python discord

(discord bot python)

代码是,如果某人聊天,如果该人在玩《守望先锋》,他/她将被提升为玩家角色,否则,他或她将被删除,否则将不会发生任何事情。但是我正在寻找一种无需聊天即可识别正在玩的游戏的方法。有人可以帮我吗?

@client.event
async def on_message(message):
    man = message.author.activity.name
    role = discord.utils.get(message.guild.roles, name="Gamer")
    if man == "Overwatch":
        await message.author.add_roles(role)
    else:
        await message.author.remove_roles(role)

2 个答案:

答案 0 :(得分:0)

只要成员更改其活动,就会触发on_member_update事件:

(df.count()+df.isnull().sum())==df.isnull().count()

答案 1 :(得分:0)

您需要调查on_member_update()事件。像这样:

@client.event
async def on_member_update(prev, cur):
    role = discord.utils.get(cur.guild.roles, name="Gamer")
    games = ["overwatch", "rocket league", "minecraft"]
    # make sure game titles are lowercase

    if cur.activity and cur.activity.name.lower() in games:
            await cur.add_roles(role)

    # only add the rest if you want them to have the role for the duration of them
    # playing a game
    elif prev.activity and prev.activity.name.lower() in games and not cur.activity:
            if role in cur.roles: # check they already have the role, as to not throw an error
                await cur.remove_roles(role)

参考: