Stability Commit with connections to Discord user

This commit is contained in:
Rafael Vargas 2022-02-24 16:09:45 -04:00
parent 63d86e23f9
commit 5312a729e9
2 changed files with 23 additions and 3 deletions

View File

@ -16,7 +16,10 @@ class Music(commands.Cog):
async def on_ready(self) -> None: async def on_ready(self) -> None:
"""Load a player for each guild that the Bot are""" """Load a player for each guild that the Bot are"""
for guild in self.__bot.guilds: for guild in self.__bot.guilds:
self.__guilds[guild] = Player(self.__bot, guild) player = Player(self.__bot, guild)
await player.force_stop()
self.__guilds[guild] = player
print(f'Player for guild {guild.name} created') print(f'Player for guild {guild.name} created')
@commands.Cog.listener() @commands.Cog.listener()
@ -175,10 +178,18 @@ class Music(commands.Cog):
@commands.command(name='reset', help=help.HELP_RESET, description=help.HELP_RESET_LONG, aliases=['resetar']) @commands.command(name='reset', help=help.HELP_RESET, description=help.HELP_RESET_LONG, aliases=['resetar'])
async def reset(self, ctx) -> None: async def reset(self, ctx) -> None:
player = self.__get_player(ctx) player = self.__get_player(ctx)
if player != None: try:
await player.force_stop()
await player.stop() await player.stop()
self.__guilds[ctx.guild] = Player(self.__bot, ctx.guild)
player = self.__get_player(ctx)
player.force_stop()
except Exception as e:
print('Reset Error: {e}')
self.__guilds[ctx.guild] = Player(self.__bot, ctx.guild) self.__guilds[ctx.guild] = Player(self.__bot, ctx.guild)
player = self.__get_player(ctx)
print(f'Player for guild {ctx.guild} created')
async def __send_embed(self, ctx, title='', description='', colour='grey') -> None: async def __send_embed(self, ctx, title='', description='', colour='grey') -> None:
try: try:

View File

@ -244,6 +244,15 @@ class Player(commands.Cog):
await self.__guild.voice_client.disconnect() await self.__guild.voice_client.disconnect()
return True return True
async def force_stop(self) -> None:
try:
self.__guild.voice_client.stop()
await self.__guild.voice_client.disconnect()
self.__playlist.clear()
self.__playlist.loop_off()
except Exception as e:
print(f'Force Stop Error: {e}')
async def pause(self) -> bool: async def pause(self) -> bool:
if self.__guild.voice_client == None: if self.__guild.voice_client == None:
return False return False
@ -339,7 +348,7 @@ class Player(commands.Cog):
result = self.__playlist.remove_song(position) result = self.__playlist.remove_song(position)
return result return result
def __format_embed(self, info=dict, title='', position='Playing Now') -> discord.Embed: def __format_embed(self, info: dict, title='', position='Playing Now') -> discord.Embed:
"""Configure the embed to show the song information""" """Configure the embed to show the song information"""
embedvc = discord.Embed( embedvc = discord.Embed(
title=title, title=title,