I'm making a discord bot for playing music (ik very unoriginal) and everytime I try to play music, it gives this error:
2023-02-18 12:31:54 INFO discord.player ffmpeg process 4024 has not terminated. Waiting to terminate...
2023-02-18 12:31:54 INFO discord.player ffmpeg process 4024 should have terminated with a return code of -9.
It is in the voice chat and didn't play anything. Here's my code if you need it:
print("defining functions")
import discord, pytube, os, threading
from moviepy import editor
from discord.ext.commands import Bot
intents=discord.Intents.default()
intents.message_content = True
intents.voice_states = True
bot = Bot("b!",intents=intents)
check = False
token = "redacted"
@bot.command()
async def play(ctx, arg):
await ctx.send("Downloading...")
try:
yt = pytube.YouTube(arg)
print("STREAM: "+str(yt.streams.filter(only_audio=True,mime_type="audio/webm",type="audio",abr="160kbps")))
def download(yt):
print("DOWNLOADING STREAM TO AUDIO.WEBM")
yt.streams.filter(only_audio=True,mime_type="audio/webm",type="audio",abr="160kbps").order_by("abr").first().download(filename="audio.webm")
print("EXPORTING TO MP3")
editor.AudioFileClip("audio.webm").write_audiofile("audio.webm"[:-5] + ".mp3")
os.remove("audio.webm")
print("DONE")
thread = threading.Thread(target=download, args=(yt,))
thread.start()
thread.join()
try:
channel = ctx.author.voice.channel
try:
vc = await channel.connect()
except Exception:
ctx.send("already in vc, one sec")
except Exception:
pass
vc.play(discord.FFmpegPCMAudio(source="audio.mp3", executable="./ffmpeg"))
except Exception:
pass
bot.run(token)
It worked on my computer in VS Code, but I wanted to test it on Replit and only there I got the error. I tried:
- Reinstalling discord, pynacl, even pytube and moviepy.
- Using a local copy of ffmpeg on replit, see line 36.
- Adding the intents that were described in a different thread.
One thing that always happens is the exit code being -9 but the process number changing (ofc). I saw a GitHub Issue about this too which is not showing a fix so how do I fix that?