Sad1que
Sad1que

Reputation: 47

Get stream info of a user from Discord python API

I want to post a notification when a member of the guild (discord server if you prefer) start streaming (twitch, youtube...) but I have trouble to use https://discordpy.readthedocs.io/en/latest/api.html#streaming. Can you tell me for exemple how to retrieve the stream URL of a user using this class ?

When I print user.activities, I only get the stream name because I'm using the class Activities. But how to use the class Streaming from the link I provided you to retrieve informations about the stream of users ?

Thanks

Upvotes: 1

Views: 1416

Answers (1)

Łukasz Kwieciński
Łukasz Kwieciński

Reputation: 15689

Member.activities is a tuple of discord.BaseActivities, you can loop through them and check if it's a discord.Streaming instance and use the url attribute

member = # Any `discord.Member` instance
acts = member.activities

for act in acts: # Looping though every activity
    if isinstance(act, discord.Streaming): # Making sure it's the correct activity
        url = act.url

You can also use the Member.activity attribute if the user has only one activity

act = member.activity

if isinstance(act, discord.Streaming):
    url = act.url

Reference:

Upvotes: 1

Related Questions