@NoGrisha
Точка.

Не проигрывается музыка discord.py и youtube_dl? Что не так?

Не проигрывается музыка. Выводит в консоль только:[youtube] yry1293OM_w: Downloading webpage, но ничего не производится. Жду уже час...Вот код:
@bot.command()
async def play(ctx, url:str):

    if not ctx.guild:
        e = discord.Embed(
                title = 'Ошибка!',
                description = 'Эта команда не работает в личных сообщениях',
                timestamp = ctx.message.created_at,
                color = discord.Colour.from_rgb(255, 0, 0)
            )
        await ctx.reply(embed = e)
        return

    voice_channel = ctx.author.voice.channel

    if voice_channel is not None:
        if ctx.voice_client is None:
            await voice_channel.connect()
        else:
            await ctx.voice_client.move_to(voice_channel)

        ctx.voice_client.stop()
        FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5','options': '-vn'}
        YDL_OPTIONS = {'format': 'bestaudio'}
        vc = ctx.voice_client
        print(0)

        with youtube_dl.YoutubeDL(YDL_OPTIONS) as ydl:
            print(1)
            info = ydl.extract_info(str(url), download = False)
        url2 = info['formats'][0]['url']
        source =await discord.FFmpegOpusAudio.from_probe(source = url2, **FFMPEG_OPTIONS)
        print(2)
        vc.play(source)
    else:
        await ctx.reply("Ты должен находиться в каком-то голосовом канале!")

Может кто-то чем-то сможет помочь...
  • Вопрос задан
  • 420 просмотров
Пригласить эксперта
Ответы на вопрос 1
JiMoon
@JiMoon
меня тут ненавидят, потому что я говнокодер.
попробуй мой код, может быть сработает:
@bot.command()
	async def play(self, ctx, url: str):
		song_there = os.path.isfile('song.mp3')
		try:
			if song_there:
				os.remove('song.mp3')
				print('[Voice] Удаляю старый файл...')
		except PermissionError:
			print('[Voice] Не удалось удалить старый файл')

		await ctx.send('Пожалуйста, ожидайте...')

		voice = discord.utils.get(self.client.voice_clients, guild = ctx.guild)


		with youtube_dl.YoutubeDL(ydl_opts) as ydl:
			print('[Voice] Загружаю музыку...')
			ydl.download([url])

		for file in os.listdir('./'):
			if file.endswith('.mp3'):
				name = file
				print(f'[Voice] Переименовываю файл: {name}')
				os.rename(file, 'song.mp3')

		voice.play(discord.FFmpegPCMAudio('song.mp3'), after = lambda e: print(f'[Voice] {name} закончила свое проигрывание'))
		voice.source = discord.PCMVolumeTransformer(voice.source)
		voice.source.volume = 0.07

		await ctx.send(f'Сейчас играет: {url}')

и кстати, если вы пишите не в блокноте, то выделите весь мой код кроме @bot.command() и нажмите Shift + Tab
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
17 апр. 2024, в 00:48
35000 руб./за проект
17 апр. 2024, в 00:13
800 руб./за проект
17 апр. 2024, в 00:06
240000 руб./за проект