async def on_ready(): voice_clients[0] = MockVoiceClient() for guild in client.guilds: try: guilddb = await objects.get(Guild, Guild.guild_id == guild.id) except Guild.DoesNotExist: continue if not guilddb.voice_channel or not guilddb.enabled: continue channel = client.get_channel(guilddb.voice_channel) if not channel or not isinstance(channel, discord.VoiceChannel): continue try: if len(channel.members) >= 1: voice_clients[guilddb.voice_channel] = await channel.connect() else: muted_voice_clients[guilddb.voice_channel] =\ await channel.connect() except (AttributeError, discord.Forbidden, discord.NotFound): continue logger.info("Joined all guilds from the database.") loop.create_task(radio_task())
async def radio_task(): """The task that will infinitely supply the radio with songs.""" playlist = PlaylistGeneration() await playlist.wait_for() while True: preload, file_name, length = playlist.next() loop.create_task(handle_playing_and_game(preload, file_name)) await asyncio.sleep(length)
async def handle_playing_and_game(preload, file_name): """Handles playing the song and setting the game.""" for voice_client in voice_clients.values(): if voice_client.is_playing(): loop.create_task(handle_when_not_playing(voice_client, preload)) else: voice_client.play(PreloadedBytesHandler(preload)) await client.change_presence(activity=discord.Game(file_name))
def __init__(self): self.ready = False self.playlist = [] self.songs_since_jingle = 0 self.songs_before_jingle = config['radio_config'][ 'songs_before_jingle'] self.songs_in_memory = config['radio_config']['songs_in_memory'] self.last_song = "" loop.create_task(self.playlist_generation())
def __init__(self): self.audio_source = None loop.create_task(self.mock_read())
def next(self): """Gets the next song from the playlist.""" item = self.playlist[0] del self.playlist[0] loop.create_task(self.playlist_generation()) return item
async def __call__(self, *args, **kwargs): try: for hook in self.client.hooks[self.event_name]: loop.create_task(hook(*args, **kwargs)) except KeyError: pass