From c22ad4e506967a7cfc830befb9bd03b3fc657f98 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 8 Aug 2023 10:26:37 -0400 Subject: [PATCH] fix: hopefully fixed the cog not loading --- galaxy/galaxy.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/galaxy/galaxy.py b/galaxy/galaxy.py index 87f23cc..05095e9 100644 --- a/galaxy/galaxy.py +++ b/galaxy/galaxy.py @@ -1,3 +1,4 @@ +import re import subprocess from datetime import datetime import discord @@ -88,13 +89,26 @@ class Galaxy(commands.Cog): coco = app_commands.Group(name='coco', guild_only=True, description="This group handles the autoreact functionality.") + def extract_id(input_string): + match = re.search(r'(?<=:)\d+(?=>)', input_string) + if match: + return match.group() + else: + return input_string + @coco.command(name="emoji") @app_commands.describe(emoji="Which emoji are you setting Coco to use?") - async def coco_emoji(self, interaction: discord.Interaction, emoji: discord.Emoji = None): + async def coco_emoji(self, interaction: discord.Interaction, emoji: str = None): """Sets Coco's emoji.""" if emoji: - await self.config.guild(interaction.guild).cocoemoji.set(emoji.id) - embed=discord.Embed(color=await self.bot.get_embed_color(None), description=f"Coco's emoji has been set to {emoji} ({emoji.id}).") + emoji_id = self.extract_id(emoji) + try: + emoji_obj = interaction.guild.fetch_emoji(emoji_id) + except discord.NotFound or discord.HTTPException as error: + await interaction.response.send_message(content="You're trying to set the coco emoji to an emoji I don't have access to!", ephemeral=True) + return + await self.config.guild(interaction.guild).cocoemoji.set(emoji_obj.id) + embed=discord.Embed(color=await self.bot.get_embed_color(None), description=f"Coco's emoji has been set to {emoji_obj} ({emoji_obj.id}).") await interaction.response.send_message(embed=embed) else: await self.config.guild(interaction.guild).cocoemoji.set(1028535684757209118)