Answer the question
In order to leave comments, you need to log in
Discord bot won't start playing the track, what's wrong?
the music bot for discord does not start playing the track, but simply writes an error in the chat of the video from YouTube, it downloads but does not start playing
a piece of code:
@bot.command(name='go', help='Выбор видео с ютуба, звуковая дорожка которого будет воспроизводится.')
async def go(ctx, url):
try:
server = ctx.message.guild
voice_channel = server.voice_client
async with ctx.typing():
filename = await YTDLSource.from_url(url, loop=bot.loop)
voice_channel.play(discord.FFmpegPCMAudio(executable='ffmpeg.exe', source=filename))
await ctx.send('СЕЙЧАС ИГРАЕТ: {}'.format(filename))
except:
await ctx.send("Не удалось выполнить команду, обратитесь к разработчику")
ytdl = youtube_dl.YoutubeDL(ytdl_format_options)
class YTDLSource(discord.PCMVolumeTransformer):
def __init__(self, source, *, data, volume=0.5):
super().__init__(source, volume)
self.data = data
self.title = data.get('title')
self.url = ""
@classmethod
async def from_url(cls, url, *, loop=None, stream=False):
loop = loop or asyncio.get_event_loop()
data = await loop.run_in_executor(None, lambda: ytdl.extract_info(url, download=not stream))
if 'entries' in data:
data = data['entries'][0]
filename = data['title'] if stream else ytdl.prepare_filename(data)
return filename
Answer the question
In order to leave comments, you need to log in
Actually, the error was not in the bot itself, as I thought, but here:
async with ctx.typing():
filename = await YTDLSource.from_url(url, loop=bot.loop)
voice_channel.play(discord.FFmpegPCMAudio(executable='ffmpeg.exe', source=filename))
^^^^^^^^^
The telepaths are in quarantine, so you'll have to find the error message yourself.
For example, using the traceback module. You import it, and then in except you write something like
except:
await ctx.send("Не удалось выполнить команду:\n" + traceback.format_exc())
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question