fix(emojiinfo): use aiohttp.ClientSession

This commit is contained in:
Seaswimmer 2024-05-08 14:30:07 -04:00
parent 7ae8226ca5
commit 80dcfea95e
Signed by untrusted user: cswimr
GPG key ID: 5D671B5D03D65A7F

View file

@ -1,6 +1,7 @@
import io
from typing import Any, Literal
import aiohttp
import discord
from colorthief import ColorThief
from red_commons.logging import RedTraceLogger, getLogger
@ -41,7 +42,8 @@ class EmojiInfo(commands.Cog):
return emoji_url
async def fetch_primary_color(self, emoji_url: str) -> discord.Color | None:
async with self.bot.http_session.get(emoji_url) as response:
async with aiohttp.ClientSession() as session:
async with session.get(emoji_url) as response:
if response.status != 200:
return None
image = await response.read()
@ -52,6 +54,7 @@ class EmojiInfo(commands.Cog):
@commands.hybrid_command(name="emoji")
async def emoji(self, ctx: commands.Context, emoji: str, ephemeral: bool = False) -> None:
"""Retrieve information about an emoji."""
await ctx.defer(ephemeral=ephemeral)
emoji: discord.PartialEmoji = discord.PartialEmoji.from_str(value=emoji)
if emoji.is_unicode_emoji():
emoji_url = await self.fetch_twemoji(unicode_emoji=emoji.name)