Skip to content Skip to sidebar Skip to footer

Recognizing A Game That Someone Is Playing Without Chatting(discord Bot Python)

(discord bot python) The code is that if someone chats anything, if the person is playing Overwatch, he or she will be promoted to the role of Gamer, and if not, he or she will be

Solution 1:

You'll want to look into the on_member_update() event. Something like so:

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

References:


Solution 2:

The on_member_update event is triggered whenever a member changes their activities:

@client.event
async def on_member_update(before, after)
    role = discord.utils.get(after.guild.roles, name="Gamer")
    if before.activities != after.activities:
        name = "Overwatch"
        before_name = any(activity.name for activity in before.activities)
        after_name = any(activity.name for activity in after.activities)
        if not before_name and after_name:
            await after.add_roles(role)
        elif before_name and not after_name:
            await after.remove_roles(role)

Post a Comment for "Recognizing A Game That Someone Is Playing Without Chatting(discord Bot Python)"