aboutsummaryrefslogtreecommitdiffstats
path: root/bot/cogs/gif.py
blob: 559e0eafa0a55c2e88c47c27c4afb689dd54090d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from os import environ

import aiohttp
from discord.ext import commands


class Gif:

    """
    A cog to fetch a random spooky gif from the web!
    """

    def __init__(self, bot):
        self.bot = bot
        self.GIPHY_TOKEN = environ.get('GIPHY_TOKEN')

    @commands.command()
    async def gif(self, ctx):
        async with aiohttp.ClientSession() as session:
            params = {'api_key': self.GIPHY_TOKEN, 'tag': 'halloween', 'rating': 'g'}
            # Make a GET request to the Giphy API to get a random halloween gif.
            async with session.get('http://api.giphy.com/v1/gifs/random', params=params) as resp:
                data = await resp.json()
            url = data['data']['url']
            await ctx.send(url)


def setup(bot):
    bot.add_cog(Gif(bot))