discord bot returns "TypeError: str, bytes or bytearray expected, not NoneType" after sometime

Viewed 117

My discord bot returns this error after calling an event sometimes. I cant figure out why because it handles the event correctly sometimes and sometimes don't this is the error:

Exception in voice thread Thread-17
Traceback (most recent call last):
  File "C:\Users\conta\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\player.py", line 603, in run
    self._do_run()
  File "C:\Users\conta\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\player.py", line 596, in _do_run
    play_audio(data, encode=not self.source.is_opus())
  File "C:\Users\conta\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\voice_client.py", line 638, in send_audio_packet
    self.socket.sendto(packet, (self.endpoint_ip, self.voice_port))
TypeError: str, bytes or bytearray expected, not NoneType

and this is the part of the code that is giving me headaches:

 caminho = "PATH"
    list_of_songs=["{}\olhaele.wav".format(caminho),"{}\miau.wav".format(caminho)]

    @client.event
    async def on_voice_state_update(member,before,after):
        if member.bot:
            return
        if before.channel is None and after.channel is not None:
            channel = after.channel
            vc = await channel.connect()
            vc.play(discord.FFmpegPCMAudio(source=random.choice(list_of_songs)))
            # Sleep while audio is playing.
            while vc.is_playing():
                time.sleep(1)
            await vc.disconnect()

I encoded the songs properly like the documentation says (16bit 48KHz PCM)

even if I use FFmpegOpusAudio the same error is presented

0 Answers
Related