diff --git a/cogs/fun/eightball.py b/cogs/fun/eightball.py index 0afd508..3625e8c 100644 --- a/cogs/fun/eightball.py +++ b/cogs/fun/eightball.py @@ -1,4 +1,5 @@ import random +import discord from discord.ext import commands def eightball_command(): diff --git a/cogs/media/mcquote.py b/cogs/media/mcquote.py index f55c1b3..3d683a3 100644 --- a/cogs/media/mcquote.py +++ b/cogs/media/mcquote.py @@ -3,7 +3,7 @@ import os import tempfile import discord from discord.ext import commands -import requests +import aiohttp import random def mcquote_command(): @@ -70,11 +70,13 @@ def mcquote_command(): mc_quote_url = f'https://skinmc.net/achievement/{random_number}/Achievement+Unlocked!/{quote_text}' try: - response = requests.get(mc_quote_url) - response.raise_for_status() + async with aiohttp.ClientSession() as session: + async with session.get(mc_quote_url) as response: + response.raise_for_status() + content = await response.read() with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as temp_file: - temp_file.write(response.content) + temp_file.write(content) temp_file_path = temp_file.name embed = discord.Embed( @@ -101,7 +103,7 @@ def mcquote_command(): await context.channel.send(file=file) os.remove(temp_file_path) - except requests.exceptions.RequestException: + except aiohttp.ClientError: embed = discord.Embed( title="Error", description="Failed to generate Minecraft quote. Please try again later.",