Files

27 lines
838 B
Python
Raw Permalink Normal View History

2019-10-08 17:37:09 -07:00
from redbot.core import commands
import aiohttp
2019-10-08 17:37:09 -07:00
class DadJokes(commands.Cog):
"""Random dad jokes from icanhazdadjoke.com"""
async def red_delete_data_for_user(self, **kwargs):
""" Nothing to delete """
return
2019-10-08 17:37:09 -07:00
def __init__(self, bot):
self.bot = bot
@commands.command()
async def dadjoke(self, ctx):
"""Gets a random dad joke."""
try:
async with aiohttp.request("GET", "https://icanhazdadjoke.com/", headers={"Accept": "text/plain"}) as r:
if r.status != 200:
return await ctx.send("Oops! Cannot get a dad joke...")
result = await r.text(encoding="UTF-8")
except aiohttp.ClientConnectionError:
return await ctx.send("Oops! Cannot get a dad joke...")
await ctx.send(f"`{result}`")