I
I
Icir2022-01-27 11:39:13
Python
Icir, 2022-01-27 11:39:13

How to interact with mp3 files through code? (python)?

I'm writing a discord bot, and I want to add the function of playing a record and rewinding/restarting it, etc., but I don't quite understand how to interact with an mp3 file. Here is my current code:

@bot.command(name = 'restart', help = 'Команда заново проигрывает видео')
async def restart(ctx):  
    voice = discord.utils.get(bot.voice_clients, guild=server)
    sound = open('sound.mp3')
    if voice.is_playing:
            sound.seek(0)
            await ctx.channel.send('Запись перезапущена')
    else:
        await ctx.channel.send('Сейчас ничего не воспроизводится')

The essence of this code is that if something is played, then it starts again, if not, then an error is displayed stating that nothing is being played. But the problem is that for some reason the code works, but the seek itself does not give any effect, the recording went on and continues to go.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2022-01-27
@Icir

You opened a file for reading as a sequence of bytes and put your open file pointer at the beginning.
Question: how will this affect the reading of the file by discord if it opens the file on its own?
That's right, no way. Just stop playing and start it again.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question