Skip to content

Commit ba3efe6

Browse files
authored
Fix adding new reactions to existing messages (#143)
* fix adding new reactions to existing messages * change order of steps to add new reaction
1 parent e0d7569 commit ba3efe6

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.5.1b
1+
3.5.2

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Reaction Light - Changelog
22

3+
### 3.5.2
4+
- Fix adding new reactions to reaction messages ([#142](https://github.com/eibex/reaction-light/issues/142) closed by [#143](https://github.com/eibex/reaction-light/pull/143) by [eibex](https://github.com/eibex))
5+
36
### 3.5.1
47
- Add ARM Docker build ([#141](https://github.com/eibex/reaction-light/issues/141))
58

cogs/message.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -650,15 +650,6 @@ async def edit_reaction(
650650
return
651651

652652
if action == "add":
653-
try:
654-
# Check that the bot can actually use the emoji
655-
await message_to_edit.add_reaction(reaction)
656-
except disnake.HTTPException:
657-
await inter.edit_original_message(
658-
content=self.bot.response.get("new-reactionrole-emoji-403", guild_id=inter.guild.id)
659-
)
660-
return
661-
662653
try:
663654
react = self.bot.db.add_reaction(message_to_edit.id, role.id, sanitize_emoji(reaction))
664655
except DatabaseError as error:
@@ -670,13 +661,34 @@ async def edit_reaction(
670661
)
671662
return
672663

664+
try:
665+
# Try to add the reaction, this will fail if the bot cannot actually use the emoji
666+
await message_to_edit.add_reaction(reaction)
667+
except disnake.HTTPException:
668+
await inter.edit_original_message(
669+
content=self.bot.response.get("new-reactionrole-emoji-403", guild_id=inter.guild.id)
670+
)
671+
try:
672+
# We remove the db entry since the edit failed
673+
react = self.bot.db.remove_reaction(message_to_edit.id, sanitize_emoji(reaction))
674+
except DatabaseError as error:
675+
await self.bot.report(
676+
self.bot.response.get("db-error-add-reaction", guild_id=inter.guild.id).format(
677+
channel_mention=message_to_edit.channel.mention, exception=error
678+
),
679+
inter.guild.id,
680+
)
681+
return
682+
return
683+
673684
if not react:
674685
await inter.edit_original_message(
675686
content=self.bot.response.get("reaction-edit-already-exists", guild_id=inter.guild.id)
676687
)
677688
return
678689

679690
await inter.edit_original_message(content=self.bot.response.get("reaction-edit-add-success", guild_id=inter.guild.id))
691+
680692
elif action == "remove":
681693
try:
682694
await message_to_edit.clear_reaction(reaction)

0 commit comments

Comments
 (0)