diff --git a/voicelink/player.py b/voicelink/player.py index 2f7efc8..e08d349 100644 --- a/voicelink/player.py +++ b/voicelink/player.py @@ -448,10 +448,7 @@ class Player(VoiceProtocol): async def invoke_controller(self): """Sends or updates the music controller message in the designated channel.""" - if not self.settings.get('controller', True): - return - - if self._updating or not self.channel: + if not self.settings.get('controller', True) or self._updating or not self.channel: return self._updating = True @@ -460,8 +457,7 @@ class Player(VoiceProtocol): embed, view = self.build_embed(self.current), InteractiveController(self) if not self.controller: if request_channel_data := self.settings.get("music_request_channel"): - channel = self.bot.get_channel(request_channel_data.get("text_channel_id")) - if channel: + if channel := self.bot.get_channel(request_channel_data.get("text_channel_id")): try: self.controller = await channel.fetch_message(request_channel_data.get("controller_msg_id")) await self.controller.edit(embed=embed, view=view) @@ -473,7 +469,11 @@ class Player(VoiceProtocol): self.controller = await dispatch_message(self.context, content=embed, view=view, delete_after=None, requires_fetch=True) elif not await self.is_position_fresh(): - await self.controller.delete() + try: + await self.controller.delete() + except errors.NotFound: + self.controller = None + self.controller = await dispatch_message(self.context, content=embed, view=view, delete_after=None, requires_fetch=True) else: diff --git a/voicelink/utils.py b/voicelink/utils.py index b5793b8..daca3aa 100644 --- a/voicelink/utils.py +++ b/voicelink/utils.py @@ -27,10 +27,10 @@ import socket import discord from itertools import zip_longest -from typing import Dict, Optional +from typing import Dict, Optional, Union from timeit import default_timer as timer from discord.ext import commands -from typing import Union +from discord.utils import MISSING from .mongodb import MongoDBHandler from .language import LangHandler @@ -301,9 +301,9 @@ async def dispatch_message( ctx: Union[commands.Context, discord.Interaction, TempCtx], content: Union[str, discord.Embed] = None, *params, - view: discord.ui.View = None, - file: discord.File = None, - delete_after: float = None, + view: Optional[discord.ui.View] = None, + file: Optional[discord.File] = None, + delete_after: Optional[float] = MISSING, ephemeral: bool = False, requires_fetch: bool = False ) -> Optional[discord.Message]: @@ -354,7 +354,7 @@ async def dispatch_message( send_kwargs["view"] = view if "delete_after" in send_func.__code__.co_varnames: - if not delete_after and settings and ctx.channel.id == settings.get("music_request_channel", {}).get("text_channel_id"): + if delete_after is MISSING and settings and ctx.channel.id == settings.get("music_request_channel", {}).get("text_channel_id"): delete_after = 10 send_kwargs["delete_after"] = delete_after