A
A
Angeloffy2021-11-13 13:08:39
Python
Angeloffy, 2021-11-13 13:08:39

How to get list of games from all discord py users?

Good day, I have a piece of code:

@commands.command()        
    async def gameinfo(self, ctx):
        game_list = []
        for member in ctx.guild.members:
            game_list += member.activities
            print(game_list['Game name'])


TypeError :

list indices must be integers or slices, not str
[<CustomActivity name='беги' emoji=None>, <Game name='Visual Studio Code'>]


Need to get - Game name

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2021-11-13
@Vindicar

If you don't know what attributes an object has, dir() and the documentation will help.

activities = sum([], (member.activities for member in ctx.guild.members))
game_names = [item.name for item in activities if instanceof(item, discord.Game)]
#если нужно только уникальные:
game_names = set(game_names)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question