From 4f66c3705ad0933ea9a8c00e0baa8de8eaae232d Mon Sep 17 00:00:00 2001 From: neoarz Date: Sat, 4 Oct 2025 18:43:06 -0400 Subject: [PATCH] fix(8ball && mcquote): fixes Replaces the synchronous requests library with aiohttp in mcquote.py to enable asynchronous HTTP requests, improving performance and compatibility with async Discord bots. Also updates exception handling to use aiohttp.ClientError. Adds missing discord import in eightball.py. --- cogs/fun/eightball.py | 1 + cogs/media/mcquote.py | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) 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.",