#Can someone help with a Python 3 bot code error?
49 messages · Page 1 of 1 (latest)
and does the bot output anythin in the console or the log when it goes silent?
there also is a possibility that after some time an exception in your play_song_loop function accours wich silently stops it.
No, like an AFK channel that's automated?
That is turned off
Can you explain this a little simpler?
Is that easy to fix?
what ide do you use?
Ide? I just run a command via CMD
And then I select the .py file that has all the info in that file
okay and does the cmd return anything or do you close it after you started the bot?
Yeah it just says, bot is online, playing etc
But the funny thing is that I let this CMD open 24/7
I can't close the CMD or the bot leaves the vc haha
I literally have to let a PC run day and night, which sucks too, I'd love to host it online somewhere if that's possible
But if it would stop going silent, that would be an immense help already
okay good. did you see anything in the cmd when it went silent?
seems like it disconnected from the voice channel
Yes, and I wonder why
There's no way it gets disconnected by another bot or a permission
It says nextcord.errors so I'm wondering what that means
okay basically the error is that nextcord tried to run a voice related action wich in this case would be playing a song while it wasnt connected to audio
i think somtimes discord connection to vc has problems here and there so you could try to implement a code that handels the case where its not connected to a voice channel
Yes but I wonder why, because when I start it from scratch, the bot joins and plays perfectly fine so I don't know why it would stop all the sudden or get disconnected. I have a really stable internet connection as well and it happened too when I have my computer on ethernet cable, my speeds are like 50 up and 900 down
I'm wondering if it's having an issue looping the file, when it's done to have it start again, that it goes wrong there
you could try replacing this with your play_song_loop function. its modified so it tries to reconnect once it disconnects plus i added some debug prints
`async def play_song_loop(voice_client: nextcord.VoiceClient):
while True:
try:
if not voice_client.is_connected():
print("Bot is not connected to a voice channel. Reconnecting...")
guild = voice_client.guild
vc = guild.get_channel(vc_id) # type: ignore
voice_client = await join_vc(guild, vc) # type: ignore
if not voice_client:
print("Failed to reconnect to voice channel.")
return
voice_client.play(nextcord.FFmpegPCMAudio(executable=ffmpeg_path, source=song_file))
while voice_client.is_playing():
await asyncio.sleep(1)
except Exception as e:
print(f"Error playing song: {e}")
finally:
if not voice_client.is_connected():
print("Bot got disconnected from the voice channel. Reconnecting...")
guild = voice_client.guild
vc = guild.get_channel(vc_id) # type: ignore
voice_client = await join_vc(guild, vc) # type: ignore
if not voice_client:
print("Failed to reconnect to voice channel.")
return`
Is that the entire code?
Is it possible that you send me the entire code I can replace in the .py file?
thats just the def_song_loop function
So where do I put that in the .py file?
uh sure wait lemme get an editor open to put it into the code
I'm sorry but I have zero knowledge on this, are you able to make the final code with your part included that I just have to run via CMD?
But I'm learning as we speak haha
ill send you the modified code but since you removed the bot token server id etc from the code you will have to enter that again ofc
Yeah sure, if you can highlight them where to put them I'll throw them back in
exactly where they were in your previous code
im only changing one function the rest of the code stays the same.
That's the code I copied and I didn't take anything out, all the information like vc ID, server ID is in a separate file called config.json
Thank you
ah okay then its fine then it should work without you having to make any changes
That's the separate json file
Cool
ill send you the code in a pastebin rq
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
this should fix the issue of it still trying to do the audio when it looses connection (it can loose connection because of a large range of things even when the internet connection is good but with the modified code it will try to reconnect everytime it looses the connection)