O
O
Oh_noo21952021-10-31 01:54:34
Python
Oh_noo2195, 2021-10-31 01:54:34

The music playback queue for the discord bot is not working, what should I do?

I tried to figure out how to implement a playback queue, but I hit a dead end, and as I understand it, I wrote nonsense. I would be glad for any help:>

If this is the most stupid mistake, then please don't hate, I'm just learning.

Here is the error, it does not always appear and the queue still does not work, but the music is played.
future: exception=AttributeError("'function' object has no attribute 'start'")>
Traceback (most recent call last):
File "/app/main.py", line 41, in audio_player_task
current.start()
AttributeError: 'function' object has no attribute 'start'
[tls @ 0x76ea2c0] Error in the pull function.
[tls @ 0x76ea2c0] IO error: Connection reset by peer
[https @ 0x76e6b40] Will reconnect at 540672 in 0 second(s), error=Connection reset by peer.
[tls @ 0x6c292c0] Error in the pull function.
[tls @ 0x6c292c0] IO error: Connection reset by peer
[https @ 0x6c25b40] Will reconnect at 540672 in 0 second(s), error=Connection reset by peer.


songs = asyncio.Queue()
play_next_song = asyncio.Event()

async def audio_player_task():
    while True:
        play_next_song.clear()
        current = await songs.get()
        current.start()
        await play_next_song.wait()

def toggle_next(self):
    client.loop.call_soon_threadsafe(play_next_song.set)

@bot.command(name='play')
async def play(ctx, *, url: str):
    if ctx.author.voice is None:
        embed = discord.Embed(title=f'подключись к каналу', color=discord.Color.red())
        bot_msg = await ctx.send(embed=embed)
        await asyncio.sleep(5)
        await bot_msg.delete()
    voice_channel = ctx.author.voice.channel        
    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", 'noplaylist': True, 'default_search': 'auto', 'forceduration': True, 'quiet': True}

    vc = ctx.voice_client

    with youtube_dl.YoutubeDL(YDL_OPTIONS) as ydl:
        info = ydl.extract_info(url, download=False)
        if 'entries' in info:
            url2 = info['entries'][0]["formats"][0]
        elif 'formats' in info:
            url2 = info["formats"][0]
        url = info["webpage_url"]
        stream_url = url2["url"]
        source = await discord.FFmpegOpusAudio.from_probe(stream_url, **FFMPEG_OPTIONS)
        vc.play(source, after = toggle_next)
        await songs.put(vc.play)

client.loop.create_task(audio_player_task())

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2021-10-31
@Oh_noo2195

vc.play(source, after = toggle_next)
await songs.put(vc.play)
You start playback by calling the vc.play() method, and then queue a reference to this method.
What do you think it should do? Because it obviously doesn't, and won't.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question