Создаю дискорд бота, когда хочу послушать музыку из ютуб, получаю ошибку: ClientException: Not connected to voice. Хотя он подключен.

vamggwp

Новичок
Пользователь
Янв 29, 2022
3
0
1
Python:
@bot.command()
async def play (ctx, url :str):
    global voice
    voice = None
    song_there = os.path.isfile("song.mp3")
    try:
        if song_there:
            os.remove("song.mp3")
    except PermissionError:
        await ctx.send("Подожди окончания или останови меня")
        return
   
    #voiceChannel = discord.utils.get(ctx.guild.voice_channels)
    voiceChannel = ctx.message.author.voice.channel
    try:
        if voice and voice.is_connected():
            await voice.move_to(voiceChannel)
        else:
            voice = await voiceChannel.connect()
    except:
        voice = await voiceChannel.connect()
    voice = ctx.message.guild.voice_client

    ydl_opts = {
        'format': 'bestaudio/best',
        'postprocessors': [{
            'key': 'FFmpegExtractAudio',
            'preferredcodec': 'mp3',
            'preferredquality': '190',
        }],
    }
    with youtube_dl.YoutubeDL(ydl_opts) as ydl:
        ydl.download([url])
    for file in os.listdir("./"):
        if file.endswith(".mp3"):
            os.rename(file, "song.mp3")
    source = await discord.FFmpegOpusAudio.from_probe("song.mp3", method='fallback')
    voice.play(source)
Некоторые ссылки работают, некоторые нет...
 
Последнее редактирование:

Форум IT Специалистов