Skip to content
Advertisement

How to display the title of the song in the embed?

Here’s my code (The bot answers are in Spanish) I was trying to put the self.info['title'] in the embed description but it was an error that said 'music_cog' object has no attribute 'info':

def search_yt(self, item):
    with YoutubeDL(self.YDL_OPTIONS) as ydl:
        try: 
            self.info = ydl.extract_info("ytsearch:%s" % item, download=False)['entries'][0]
        except Exception: 
            return False

    return {
      'source': self.info['formats'][0]['url'], 
      'title': self.info['title'],
      'channel': self.info['channel']

      }

@client.command()
async def p(self, ctx, *args):

  embed = discord.Embed(
    title = 'Reproduciendo 🎵',
    description = 'song_title'
  )

  query = " ".join(args)
    
  voice_channel = ctx.author.voice.channel
  if voice_channel is None:
        await ctx.send("Antes debes meterte a un canal de voz")
  else:
        song = self.search_yt(query)
        if type(song) == type(True):
            await ctx.send("Hubo un error al intentar reproducir la canción >-<")
        else:
            await ctx.send(embed=embed)
            await ctx.send("**Canción agregada con exito**")
            self.music_queue.append([song, voice_channel])
            
            if self.is_playing == True:
              await ctx.send('La canción se agrego a la lista de reproducción')

            else:
              await self.play_music()
              await ctx.send("**Reproduciendo**")

Advertisement

Answer

Write song = self.search_yt(query) before the embed initialization and create the embed like this:

embed = discord.Embed(
  title = "Reproduciendo 🎵",
  description = song['title']
)
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement