diff options
author | 2018-10-09 11:53:06 +0200 | |
---|---|---|
committer | 2018-10-09 11:53:06 +0200 | |
commit | 92d99fbf35155b9530c55feebb81ed9e577058d0 (patch) | |
tree | ca9f4afcf887de115fb7d91ebaf65a49c9f7f820 /bot | |
parent | Implement Halloweenify feature. (diff) |
Add random spooky gif feature.
Diffstat (limited to 'bot')
-rw-r--r-- | bot/cogs/gif.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/bot/cogs/gif.py b/bot/cogs/gif.py new file mode 100644 index 00000000..559e0eaf --- /dev/null +++ b/bot/cogs/gif.py @@ -0,0 +1,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)) |