title: Python Discord Music Bot - creating a queue - automatically playing the next song
body: <p>I am making a discord music bot in python. It can already do the basics like downloading, playing music, pause, resume, stop, etc.</p>
  <p>Right now I am trying to make a QUEUE. So the bot automatically plays the next song without me manually tell him again to play some music. It already creates a list as a queue with the songs, but..</p>
  <p>My Problem: My bot does not know when the song is finished to play the next song; there is no event for the bot to play the next song. Maybe anyone knows a suitable command or how I can solve that problem?
  I am usually using the events from discord ('on_ready', 'on_message', 'on_error', ...), but I don't know a suitable for the queue.</p>
  <pre><code>import discord
  from discord.ext import commands
  import os
  import bunchi_commands
  import youtube_dl
  
  #intents
  intents = discord.Intents.default()
  intents.members = True
  intents.presences = True
  
  #variabeln
  queue = []
  
  
  #implementation
  class MyClient(discord.Client):
      #-------------------------------------------------
      async def on_message(self, message): 
          prefix = &quot;~&quot;
          if message.author != self.user:
              msg = message.content.split()
  
              voicechannel = message.author.voice.channel
              voiceclient = message.guild.voice_client
  
          #-------------(voice-commands)--------------------
              elif msg[0] == prefix+&quot;join&quot;:
                  if voiceclient and voiceclient.is_connected():
                      await voiceclient.move_to(voicechannel)
                  else:
                      await voicechannel.connect()
  
              elif msg[0] == prefix+&quot;dc&quot;:         
                  if voiceclient.is_connected():
                      await voiceclient.disconnect()
  
              elif msg[0] == prefix+&quot;play&quot;:
                  if voiceclient and voiceclient.is_connected():      # just connecting to the voicechannel and voiceclient
                      await voiceclient.move_to(voicechannel)         # 
                  else:                                               #  
                      await voicechannel.connect()                    # 
  
                  
                  url = str(message.content)[len(msg[0])+1:]          
                  dirpath = './downloadsong'                          
                  filename = 'song.mp3'                           
                  filepath = '{}/{}'.format(dirpath,filename)
  
                  if queue == []:                                      # if queue is empty (=not playing a song right now)
                      bunchi_commands.check_song(filepath)                # delete old song
                      bunchi_commands.download_song(url,filepath)         # download new song
  
                      voiceclient.play(discord.FFmpegPCMAudio(&quot;./downloadsong/song.mp3&quot;)) # play song
  
                  bunchi_commands.addqueue(queue,url)
                  print(queue)
                              
              elif msg[0] == prefix+&quot;pause&quot;:
                  if voiceclient.is_playing():
                      voiceclient.pause()
  
              elif msg[0] == prefix+&quot;resume&quot;:
                  if voiceclient.is_paused():
                      voiceclient.resume()
              
              elif msg[0] == prefix+&quot;stop&quot;:
                  voiceclient.stop()
  
      
  #---------------------------------------------------
  client = MyClient(intents=intents)
  client.run('Token')
  </code></pre>