[Python] I cannot play a mp3 file on Discord's voice channel using discord.py

Discussão em 'Python' iniciado por Stack, Dezembro 1, 2024.

  1. Stack

    Stack Membro Participativo

    I am creating a discord bot that plays lofi for me. It does not play a song for me even though it shows a green indicator on a voice channel.

    Here's what I've written:

    if message.content == "!join":
    await message.author.voice.channel.connect()
    await message.channel.send("Successfully connected")

    if message.content == "!play":
    if message.guild.voice_client is None:
    await message.channel.send("use !join")
    return

    await message.channel.send("playing a song rn")
    print('*** playing a song rn')

    message.guild.voice_client.play(discord.FFmpegPCMAudio('lofi.mp3'))


    I put FFmpeg.exe and lofi.mp3 in the same directory as this script. Also, it is strange that FFmpeg does not return any exception nor output on console although it seems to have failed to load the file. I have seen people who had the same problem, but it seems like that they get some error messages, unlike me.

    Here's the output on console after using !join

    2024-12-01 16:59:39 INFO discord.voice_state Connecting to voice...
    2024-12-01 16:59:39 INFO discord.voice_state Starting voice handshake... (connection attempt 1)
    2024-12-01 16:59:40 INFO discord.voice_state Voice handshake complete. Endpoint found: japan8946.discord.media
    2024-12-01 16:59:40 INFO discord.voice_state Voice connection complete.


    after using !play, it only displays the message I wrote:

    *** playing a song rn


    Can someone help me with this?

    Continue reading...

Compartilhe esta Página