33 regarding the guild and also defines a USER class from the
44 _BaseGUILD class.
55"""
6- from typing import Any , Coroutine , Union , List , Optional , Dict , Callable , Set
6+ from typing import Any , Coroutine , Union , List , Optional , Dict , Callable
77from typeguard import typechecked
88from datetime import timedelta , datetime
99from copy import deepcopy
@@ -429,9 +429,9 @@ class GUILD(_BaseGUILD):
429429
430430 .. note::
431431
432- Accounts are required to have *Manage Channels* and *Manage Server* permissions inside a guild for tracking to
433- fully function. *Manage Server* is needed for getting information about invite links, *Manage Channels*
434- is needed to delete the invite from the list if it has been deleted,
432+ Accounts are required to have *Manage Channels* and *Manage Server* permissions inside a guild for
433+ tracking to fully function. *Manage Server* is needed for getting information about invite links,
434+ *Manage Channels* is needed to delete the invite from the list if it has been deleted,
435435 however tracking still works without it.
436436 """
437437 __slots__ = (
@@ -481,7 +481,7 @@ async def get_invites(self) -> List[discord.Invite]:
481481
482482 return [] # Return empty on error or no permissions
483483
484- async def initialize (self , parent : Any , _init = True ) -> None :
484+ async def initialize (self , parent : Any ) -> None :
485485 """
486486 This function initializes the API related objects and
487487 then tries to initialize the MESSAGE objects.
@@ -568,7 +568,7 @@ def generate_invite_log_context(self, member: discord.Member, invite_id: str) ->
568568 }
569569
570570 @misc ._async_safe ("update_semaphore" , 1 )
571- async def update (self , init_options = None , _init = True , ** kwargs ):
571+ async def update (self , init_options = None , ** kwargs ):
572572 """
573573 Used for changing the initialization parameters,
574574 the object was initialized with.
@@ -600,23 +600,22 @@ async def update(self, init_options = None, _init = True, **kwargs):
600600 if "invite_track" not in kwargs :
601601 kwargs ["invite_track" ] = list (self .join_count .keys ())
602602
603+ messages = kwargs .pop ("messages" , self .messages + self ._messages_uninitialized )
604+
603605 if init_options is None :
604606 init_options = {"parent" : self .parent }
605607
606- # Add uninitialized servers
607- messages = kwargs .pop ("messages" , self .messages + self ._messages_uninitialized )
608- kwargs ["messages" ] = [] # Messages are updated at the end
609-
610- await misc ._update (self , init_options = init_options , _init = _init , ** kwargs )
608+ await misc ._update (self , init_options = init_options , ** kwargs )
611609
612- # Update messages
610+ _messages = []
613611 for message in messages :
614612 try :
615- await message .update (_init_options = {"parent" : self }, _init = _init )
613+ await message .update ()
614+ _messages .append (message )
616615 except Exception as exc :
617- trace (f"Unable to update message after updating GUILD, message: { message } " , TraceLEVELS .ERROR , exc )
616+ trace (f"Could not update { message } after updating { self } - Skipping message. " , TraceLEVELS .ERROR , exc )
618617
619- self ._messages = messages
618+ self ._messages = _messages
620619
621620
622621@misc .doc_category ("Guilds" )
@@ -692,7 +691,7 @@ async def initialize(self, parent: Any):
692691 )
693692
694693 @misc ._async_safe ("update_semaphore" , 1 )
695- async def update (self , init_options = None , _init = True , ** kwargs ):
694+ async def update (self , init_options = None , ** kwargs ):
696695 """
697696 .. versionadded:: v2.0
698697
@@ -721,23 +720,22 @@ async def update(self, init_options = None, _init = True, **kwargs):
721720 if "snowflake" not in kwargs :
722721 kwargs ["snowflake" ] = self .snowflake
723722
723+ messages = kwargs .pop ("messages" , self .messages + self ._messages_uninitialized )
724+
724725 if init_options is None :
725726 init_options = {"parent" : self .parent }
726727
727- messages = kwargs .pop ("messages" , self .messages )
728- kwargs ["messages" ] = [] # Messages are updated at the end
729-
730- await misc ._update (self , init_options = init_options , _init = _init , ** kwargs )
728+ await misc ._update (self , init_options = init_options , ** kwargs )
731729
732- # Update messages
730+ _messages = []
733731 for message in messages :
734732 try :
735- await message .update (_init_options = {"parent" : self }, _init = _init )
733+ await message .update ()
734+ _messages .append (message )
736735 except Exception as exc :
737- trace (f"Unable to update message after updating GUILD, message: { message } " , TraceLEVELS .ERROR , exc )
736+ trace (f"Could not update { message } after updating { self } - Skipping message. " , TraceLEVELS .ERROR , exc )
738737
739-
740- self ._messages = messages
738+ self ._messages = _messages
741739
742740
743741@misc .doc_category ("Auto objects" )
@@ -1097,7 +1095,7 @@ async def _advertise(self):
10971095 return GUILD_ADVERT_STATUS_SUCCESS
10981096
10991097 @misc ._async_safe ("_safe_sem" , 1 )
1100- async def update (self , init_options = None , _init = True , ** kwargs ):
1098+ async def update (self , init_options = None , ** kwargs ):
11011099 """
11021100 Updates the object with new initialization parameters.
11031101
@@ -1110,6 +1108,8 @@ async def update(self, init_options = None, _init = True, **kwargs):
11101108
11111109 await self ._close ()
11121110 try :
1113- return await misc ._update (self , init_options = init_options , _init = _init , ** kwargs )
1114- finally :
1111+ return await misc ._update (self , init_options = init_options , ** kwargs )
1112+ except Exception :
1113+ self .cache .clear ()
11151114 await self .initialize (self .parent ) # Reopen any async related connections
1115+ raise
0 commit comments