From 1f3b12501bcc62f7d18490296471271cf0dbd36d Mon Sep 17 00:00:00 2001 From: Nick Jungmann Date: Mon, 20 Feb 2023 21:43:31 +0100 Subject: [PATCH] Fixed notification on OnMemberJoin #191 --- .../src/modules/level/service/level_service.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/kdb-bot/src/modules/level/service/level_service.py b/kdb-bot/src/modules/level/service/level_service.py index 44e99a93..2acfd6fc 100644 --- a/kdb-bot/src/modules/level/service/level_service.py +++ b/kdb-bot/src/modules/level/service/level_service.py @@ -57,6 +57,7 @@ class LevelService: if level_role in member.roles: return + notification_needed = False for role in member.roles: if role.name not in level_names.to_list(): continue @@ -64,6 +65,7 @@ class LevelService: try: self._logger.debug(__name__, f"Try to remove role {role.name} from {member.name}") await member.remove_roles(role) + notification_needed = True self._logger.info(__name__, f"Removed role {role.name} from {member.name}") except Exception as e: self._logger.error(__name__, f"Removing role {role.name} from {member.name} failed!", e) @@ -75,12 +77,13 @@ class LevelService: except Exception as e: self._logger.error(__name__, f"Adding role {level_role.name} to {member.name} failed!", e) - level_settings: LevelServerSettings = self._config.get_configuration(f"LevelServerSettings_{guild.id}") - await self._message_service.send_channel_message( - self._bot.get_channel(level_settings.changed_level_notification_channel), - self._t.transform("modules.level.new_level_message").format(member.mention, level.name), - is_persistent=True, - ) + if notification_needed: + level_settings: LevelServerSettings = self._config.get_configuration(f"LevelServerSettings_{guild.id}") + await self._message_service.send_channel_message( + self._bot.get_channel(level_settings.changed_level_notification_channel), + self._t.transform("modules.level.new_level_message").format(member.mention, level.name), + is_persistent=True, + ) async def check_level(self, member: discord.Member): if member.bot: