@Romikan

Бот не играет музыку а выдаёт ошибку. Что делать?

Решил добавить возможность музыки в моём боте. Перевёл с GitHub инструкцию и не работает. Я вроде сделал всё правильно.
youtube_dl.utils.bug_reports_message = lambda: 'Ошибочка...'
ytdl_format_options = {
    'format': 'bestaudio/best',
    'restrictfilenames': True,
    'noplaylist': True,
    'nocheckcertificate': True,
    'ignoreerrors': False,
    'logtostderr': False,
    'quiet': True,
    'no_warnings': True,
    'default_search': 'auto',
    'source_address': '(тут мой айпи вставлен)' # bind to ipv4 since ipv6 addresses cause issues sometimes
}
ffmpeg_options = {
    'options': '-vn'
}
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:
            # take first item from a playlist
            data = data['entries'][0]
        filename = data['title'] if stream else ytdl.prepare_filename(data)
        return filename
@bot.command(name='leave', help='To make the bot leave the voice channel')
async def leave(ctx):
    voice_client = ctx.message.guild.voice_client
    if voice_client.is_connected():
        await voice_client.disconnect()
        await ctx.send("Бот успешно вышел из голосового канала.")
    else:
        await ctx.send("Бот не подключён к голосовому каналу.")

@bot.command(name='play_song', help='To play song')
async def play_song(ctx,url):
    if not ctx.message.author.voice:
        await ctx.send("{} не подключён к голосовому каналу".format(ctx.message.author.name))
        return
    else:
        channel = ctx.message.author.voice.channel
        await channel.connect()
        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=""))
            await ctx.send('**Сейчас играет:** {}'.format(filename))
        except:
            await ctx.send("Бот не соеденён в голосовой канал.")
@bot.command(name='pause', help='This command pauses the song')
async def pause(ctx):
    voice_client = ctx.message.guild.voice_client
    if voice_client.is_playing():
        await voice_client.pause()
    else:
        await ctx.send("В данный момент бот не играет никакое аудио.")
    
@bot.command(name='resume', help='Resumes the song')
async def resume(ctx):
    voice_client = ctx.message.guild.voice_client
    if voice_client.is_paused():
        await voice_client.resume()
    else:
        await ctx.send("В данный момент бот не играет никакое аудио")
@bot.command(name='stop', help='Stops the song')
async def stop_song(ctx):
    voice_client = ctx.message.guild.voice_client
    if voice_client.is_playing():
        await voice_client.stop()
    else:
        await ctx.send("В данный момент бот не играет никакое аудио.")
bot.run(settings['token'])

Выдаёт ошибку:
ERROR: Unable to download API page: (caused by URLError(OSError(10049, 'Требуемый адрес для своего контекста неверен', None, 10049, None)))
  • Вопрос задан
  • 83 просмотра
Пригласить эксперта
Ваш ответ на вопрос

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

Войти через центр авторизации
Похожие вопросы
18 мая 2024, в 22:58
3000 руб./за проект
18 мая 2024, в 21:07
5000 руб./за проект
18 мая 2024, в 20:58
5000 руб./за проект