Added logic to add reaction after creating auto role rule in WI #259

This commit is contained in:
2023-03-27 10:16:14 +02:00
parent 75ad07477a
commit 3c8a092f40
5 changed files with 62 additions and 20 deletions

View File

@@ -6,7 +6,7 @@ from cpl_discord.command import DiscordCommandABC
from cpl_discord.service import DiscordBotServiceABC
from cpl_query.extension import List
from cpl_translation import TranslatePipe
from discord import app_commands, Guild
from discord import app_commands
from discord.ext import commands
from discord.ext.commands import Context
@@ -312,26 +312,12 @@ class AutoRoleGroup(DiscordCommandABC):
.where(lambda r: r.emoji_name == emoji.name and int(role_id) == role.id)
.single()
)
try:
guild: Guild = self._bot.guilds.where(lambda g: g == ctx.guild).single()
channel = guild.get_channel(auto_role_from_db.discord_channel_id)
message = await channel.fetch_message(auto_role_from_db.discord_message_id)
emoji = List(discord.Emoji, guild.emojis).where(lambda x: x.name == rule.emoji_name).single()
if emoji is None:
self._logger.debug(__name__, f"Emoji {rule.emoji_name} not found")
return
await message.add_reaction(emoji)
self._logger.debug(
__name__,
f"Added reaction {rule.emoji_name} to message: {auto_role_from_db.discord_message_id}",
)
except Exception as e:
self._logger.error(
__name__,
f"Cannot add reaction {rule.emoji_name} to message: {auto_role_from_db.discord_message_id}",
e,
self._bot.loop.create_task(
await self._client_utils.react_to_message_by_auto_role_rule(
auto_role_from_db.discord_channel_id, auto_role_from_db.discord_message_id, rule, ctx.guild
)
)
await self._message_service.send_ctx_msg(
ctx,