如何在嵌入中显示歌曲的标题?
How to display the title of the song in the embed?
这是我的代码(机器人的答案是西班牙语)
我试图将 self.info['title']
放入嵌入说明中,但出现 '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**")
在嵌入初始化之前写song = self.search_yt(query)
并像这样创建嵌入:
embed = discord.Embed(
title = "Reproduciendo ",
description = song['title']
)
这是我的代码(机器人的答案是西班牙语)
我试图将 self.info['title']
放入嵌入说明中,但出现 '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**")
在嵌入初始化之前写song = self.search_yt(query)
并像这样创建嵌入:
embed = discord.Embed(
title = "Reproduciendo ",
description = song['title']
)