@Snoppybot

Как решить ошибку при написании музыкального бота для дискорда на Discord.py?

import os
import discord
from discord.ext import commands
from discord.ext.commands import Bot
import youtube_dl

bot = commands.Bot(command_prefix='!')

bot = discord.Client()

bot = Bot("!")

@bot.event
async def on_ready():
    print(bot.user)
    print(bot.user.id)
    print([c.name for c in bot.get_all_channels()])

server, server_id, name_channel = None, None, None

domains = ['https://www.youtube.com/', 'http://www.youtube.com/', 'https://youtu.be/', 'http://youtu.be/']
async def check_domains(link):
   for x in domains:
       if link.startswith(x):
           return True
       return False

@bot.command()
async def play(ctx, *, command = None):
    """воспроизводит музикууу"""
    global server, server_id, name_channel
    author = ctx.author
    if command  == None:
        server = ctx.guild
        name_channel = author.voice.channel.name
        voice_channel = discord.utils.get(server.voice_channels, name = name_channel)
    params = command.split(' ')
    if len(params) == 1:
        sourse = params[0]
        server = ctx.guild
        name_channel = author.voice.channel.name
        voice_channel = discord.utils.get(server.voice_channels, name = name_channel)
        print("param 1")
    elif len(params) == 3:
        server_id = params[0]
        voice_id = params[1]
        sourse = params[2]
        try:
            server_id - int(server_id)
            voice_id = int(voice_id)
        except:
            await ctx.channel.send(f'{author.mention}, id сервера или канала войс чата должно быть числом')
            return
        print('param 3')
        server = bot.get_guild(server_id)
        voice_channel = discord.utils.get(server.voice_channels, id=voice_id)
    else:
        await ctx.channel.send (f'{author.mention} Ты еблан?Сам прочитал что написал?')
        return

    voice = discord.utils.get(bot.voice_clients, guild = server)
    if voice is None:
        await voice_channel.connect()
        voice = discord.utils.get(bot.voice_clients, guild=server)

    if sourse == None:
        pass
    elif sourse.startswith('http'):
        if not await check_domains(sourse):
            await ctx.channel.send(f'{author.mention} Ссылка запрещенна.')
            return

        song_there = os.path.isfile('music/song.webm')

        try:
            if song_there:
                os.remove('music/song.webm')
        except PermissionError:
            await ctx.channel.send (f'Системная ошибка (Недостаточно прав)')
            return

        ydl_opts = {
            'format': 'bestaudio/best',
            'postprocessors': [
                {
                    'key': 'FFmpegExtractAudio',
                    'preferredcodec': 'webm',
                    'preferredquality': '192',

                }
            ],
        }


        with youtube_dl.YoutubeDL(ydl_opts) as ydl:
            ydl.download([sourse])
        for file in os.listdir('music/'):
            if file.endswith('.webm'):
                os.rename(file, 'song.webm')
        voice.play(discord.FFmpegPCMAudio('music/song.webm'))
    else:
        voice.play(discord.FFmpegPCMAudio('music/{sourse}'))

Бот подключается к каналу в консоль выводится сообщение о том что видео загружено и тут ошибка воспроизведения.
Как ее исправить я не знаю, может кто то поможет
spoiler
ERROR: ffprobe/avprobe and ffmpeg/avconv not found. Please install one.
Ignoring exception in command play:
Traceback (most recent call last):
File "C:\Users\kola5\PycharmProjects\XD\venv\lib\site-packages\youtube_dl\YoutubeDL.py", line 2115, in post_process
files_to_delete, info = pp.run(info)
File "C:\Users\kola5\PycharmProjects\XD\venv\lib\site-packages\youtube_dl\postprocessor\ffmpeg.py", line 272, in run
filecodec = self.get_audio_codec(path)
File "C:\Users\kola5\PycharmProjects\XD\venv\lib\site-packages\youtube_dl\postprocessor\ffmpeg.py", line 166, in get_audio_codec
raise PostProcessingError('ffprobe/avprobe and ffmpeg/avconv not found. Please install one.')
youtube_dl.utils.PostProcessingError: ffprobe/avprobe and ffmpeg/avconv not found. Please install one.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\kola5\PycharmProjects\XD\venv\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\kola5\PycharmProjects\XD\music2\bot1.py", line 96, in play
ydl.download([sourse])
File "C:\Users\kola5\PycharmProjects\XD\venv\lib\site-packages\youtube_dl\YoutubeDL.py", line 2068, in download
res = self.extract_info(
File "C:\Users\kola5\PycharmProjects\XD\venv\lib\site-packages\youtube_dl\YoutubeDL.py", line 808, in extract_info
return self.__extract_info(url, ie, download, extra_info, process)
File "C:\Users\kola5\PycharmProjects\XD\venv\lib\site-packages\youtube_dl\YoutubeDL.py", line 815, in wrapper
return func(self, *args, **kwargs)
File "C:\Users\kola5\PycharmProjects\XD\venv\lib\site-packages\youtube_dl\YoutubeDL.py", line 847, in __extract_info
return self.process_ie_result(ie_result, download, extra_info)
File "C:\Users\kola5\PycharmProjects\XD\venv\lib\site-packages\youtube_dl\YoutubeDL.py", line 881, in process_ie_result
return self.process_video_result(ie_result, download=download)
File "C:\Users\kola5\PycharmProjects\XD\venv\lib\site-packages\youtube_dl\YoutubeDL.py", line 1692, in process_video_result
self.process_info(new_info)
File "C:\Users\kola5\PycharmProjects\XD\venv\lib\site-packages\youtube_dl\YoutubeDL.py", line 2050, in process_info
self.post_process(filename, info_dict)
File "C:\Users\kola5\PycharmProjects\XD\venv\lib\site-packages\youtube_dl\YoutubeDL.py", line 2117, in post_process
self.report_error(e.msg)
File "C:\Users\kola5\PycharmProjects\XD\venv\lib\site-packages\youtube_dl\YoutubeDL.py", line 628, in report_error
self.trouble(error_message, tb)
File "C:\Users\kola5\PycharmProjects\XD\venv\lib\site-packages\youtube_dl\YoutubeDL.py", line 598, in trouble
raise DownloadError(message, exc_info)
youtube_dl.utils.DownloadError: ERROR: ffprobe/avprobe and ffmpeg/avconv not found. Please install one.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:\Users\kola5\PycharmProjects\XD\venv\lib\site-packages\discord\ext\commands\bot.py", line 902, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\kola5\PycharmProjects\XD\venv\lib\site-packages\discord\ext\commands\core.py", line 864, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\kola5\PycharmProjects\XD\venv\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: DownloadError: ERROR: ffprobe/avprobe and ffmpeg/avconv not found. Please install one.

Выдает эти ошибки....
FFprobe и FFmpeg скачаны.
  • Вопрос задан
  • 106 просмотров
Пригласить эксперта
Ответы на вопрос 1
fox_12
@fox_12 Куратор тега Python
Расставляю биты, управляю заряженными частицами
ffmpeg, fprobe устанавливали чтобы они были доступны из PATH?
README.md читали?
Параметр ffmpeg_location при инициализации YoutubeDL пробовали задавать?
Ответ написан
Ваш ответ на вопрос

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

Войти через центр авторизации
Похожие вопросы