user3108489
user3108489

Reputation: 363

Python to Capture stats of games being played by members of my Discord server

I'm interested in creating a bot that captures all of the games members of my server are playing and gives me the stats so I can see which games members of my server are most interested in. Basically, when you see a users status says something like "...playing Minecraft" or "...streaming Roblox", etc. I want to capture that. My ultimate goal is to be able to enter a command like:

/getgamestats

And have it return something like:

Roblox 38
Minecraft 27
GTA 22

I found this, which seems to be a way to set a specific status, but would like to learn how to get the status. SET playing status

I'm guessing I'd also need some kind of database included to store the stats.

Upvotes: 0

Views: 364

Answers (1)

TheBiggerFish
TheBiggerFish

Reputation: 168

You can access a user's current activity with discord.Member.activity. Below is an example of accessing member activity. Be aware that the default Intents does not include presences, including the activity of members on your server.

import time
import discord

intents = discord.Intents().all()
client = discord.Client(intents=intents)

@client.event
async def on_ready():
    guild: discord.Guild = client.get_guild(GUILD_ID_HERE)
    while(True):
        for member in guild.members:
            print(member.activity)
            # access member.activity to do stuff
        time.sleep(5)

client.run(BOT_TOKEN_HERE)

Also be aware that in order to access member activity, you will need to enable privileged gateway intents on the discord developer portal.

In order to store user statistics long-term, you will need to look for your own storage solution (such as a database), as Discord does not provide past user activity.

Upvotes: 3

Related Questions