twitch.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:Bonfire 作者: Phxntxm 项目源码 文件源码
def twitch(self, ctx, *, member: discord.Member = None):
        """Use this command to check the twitch info of a user

        EXAMPLE: !twitch @OtherPerson
        RESULT: Information about their twitch URL"""
        await ctx.message.channel.trigger_typing()

        if member is None:
            member = ctx.message.author

        result = await utils.get_content('twitch', member.id)
        if result is None:
            await self.bot.say("{} has not saved their twitch URL yet!".format(member.name))
            return

        url = result['twitch_url']
        user = re.search("(?<=twitch.tv/)(.*)", url).group(1)
        twitch_url = "https://api.twitch.tv/kraken/channels/{}".format(user)
        payload = {'client_id': self.key}
        data = await utils.request(twitch_url, payload=payload)

        embed = discord.Embed(title=data['display_name'], url=url)
        if data['logo']:
            embed.set_thumbnail(url=data['logo'])

        embed.add_field(name='Title', value=data['status'])
        embed.add_field(name='Followers', value=data['followers'])
        embed.add_field(name='Views', value=data['views'])
        if data['game']:
            embed.add_field(name='Game', value=data['game'])
        embed.add_field(name='Language', value=data['broadcaster_language'])

        await self.bot.say(embed=embed)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号