0
votes

I'm trying to make my bot to send a message to a specified channel, when I start livestreaming on twitch. so far I'm fiddling with getting the right "activity" from my status, which represents, that I'm streaming. This is what I got so far :

class Stream(commands.Cog):
    def __init__(self, bot):
        self.bot = bot
        
    
    @commands.Cog.listener()
    async def on_ready(self):
        print("Streamingstatus loaded")
    
    
    @commands.Cog.listener()
    async def on_member_update(self, before, after):
        channel = self.bot.get_channel (751954378772185149)
        if after.activity is not None and after.activity.name == '#Twitch or so?' and after.id == 254375451084980224 and guild.id == 670015807551438874:
                print(before.activity)
                print(after.activity)
                if after.activity.title.startswith(#streaming) and before.activity.title != after.activity.title:
                        await channel.send("Spleens went live on twitch right now! Watch him making a fool out of himself!")

Thanks in advance for any help!^^

1

1 Answers

0
votes

Your issue is that you are checking activity.name while the correct would be to check activity.type. Also to check if a user is streaming you want to check if activity.type is discord.ActivityType.streaming. I am not completely sure what you are trying to achieve in some lines of your code, but to check if the user is streaming just do this:

@commands.Cog.listener()
async def on_member_update(self, before, after):
    try:
        activity_type = after.activity.type
    except:
        pass
    # Here we check if the user is streaming
    if activitity_type is discord.ActivityType.streaming:
        # Do X if he is streaming
    else:
        # Do Y if he is not streaming