You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importdiscord, os, ffmpeg, asynciofromdiscord.extimportcommandsfromdiscordimportFFmpegPCMAudiofrompytubefiximportYouTubefromsoundcloud_downloaderimportSoundCloudDownloaderdownloader=SoundCloudDownloader(
output_dir="C:/Users/Jude/Desktop/scripts/songs",
name_format="song",
client_id="3WvMqSrX1K9rBNLGUNhUO9KRbVOUR9uT"
)
globalVC_Channel, que, qnamesVC_Channel=Noneintents=discord.Intents.default()
intents.message_content=Truebot=commands.Bot(command_prefix='&', intents=intents)
que, qnames= [], []
asyncdefsc_play(ctx, url):
globalVC_Channel, que, qnamesifVC_ChannelisnotNone:
awaitctx.send("attempting to q")
try:
awaitctx.send("Downloading..")
result=downloader.download_track(url, overwrite=True)
awaitctx.send("sending..")
msg=awaitctx.send(files=[discord.File("C:/Users/Jude/Desktop/scripts/songs/song.mp3")])
exceptExceptionase:
awaitctx.send(f"error adding to queue, {e}" )
returnque.append(msg.attachments[0].url)
qnames.append(result['title'] ifresultand'title'inresultelse'Unknown Title')
awaitctx.send(f"added to queue! position: {len(que)}")
else:
awaitctx.send(f"downloading video..\nThis may take a minute!")
downloader.download_track(url, overwrite=True)
awaitctx.send(f"downloaded!\nsending file...")
try:
msg=awaitctx.send(files=[discord.File("C:/Users/Jude/Desktop/scripts/songs/song.mp3")])
exceptExceptionase:
awaitctx.send(f"error sending file: {e}")
os.remove("C:/Users/Jude/Desktop/scripts/songs/song.mp3")
returnos.remove("C:/Users/Jude/Desktop/scripts/songs/song.mp3")
FFMPEG_OPTIONS= {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5','options': '-vn -filter:a "volume=0.25"'}#optimised settings for ffmpeg for streamingsource=FFmpegPCMAudio(source=msg.attachments[0].url, executable="ffmpeg",**FFMPEG_OPTIONS)
vc=awaitctx.author.voice.channel.connect(self_deaf=True)
VC_Channel=vcawaitctx.send(f"playing...")
vc.play(source, after=lambdae: play_next())
asyncdefyt_play(ctx, url):
globalVC_Channel, que, qnamesifVC_ChannelisnotNone:
awaitctx.send("attempting to q")
try:
yt=YouTube(url)
ys=yt.streams.get_audio_only()
awaitctx.send("Downloading..")
ys.download(output_path="C:/Users/Jude/Desktop/scripts/songs", filename="song.m4a")
awaitctx.send("downloaded video!")
awaitctx.send("sending file")
msg=awaitctx.send(files=[discord.File("C:/Users/Jude/Desktop/scripts/songs/song.m4a")])
exceptExceptionase:
awaitctx.send(f"error adding to queue, {e}" )
returnque.append(msg.attachments[0].url)
awaitctx.send(f"added to queue! position: {len(que)}")
qnames.append(yt.title)
os.remove("C:/Users/Jude/Desktop/scripts/songs/song.m4a")
returnauthor=ctx.authorifctx.channel.id!=1169505345991872573:
returnifauthor.voiceisNone:
awaitctx.send("Be in a vc!")
returnawaitctx.send(f"downloading video..\nThis may take a minute!")
yt=YouTube(url)
ys=yt.streams.get_audio_only()
ys.download(output_path="C:/Users/Jude/Desktop/scripts/songs", filename="song.m4a")
awaitctx.send(f"downloaded!\nsending file...")
try:
msg=awaitctx.send(files=[discord.File("C:/Users/Jude/Desktop/scripts/songs/song.m4a")])
exceptExceptionase:
awaitctx.send(f"error sending file: {e}")
os.remove("C:/Users/Jude/Desktop/scripts/songs/song.m4a")
returnos.remove("C:/Users/Jude/Desktop/scripts/songs/song.m4a")
FFMPEG_OPTIONS= {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5','options': '-vn -filter:a "volume=0.25"'}#optimised settings for ffmpeg for streamingsource=FFmpegPCMAudio(source=msg.attachments[0].url, executable="ffmpeg",**FFMPEG_OPTIONS)
vc=awaitauthor.voice.channel.connect(self_deaf=True)
VC_Channel=vcawaitctx.send(f"playing...")
vc.play(source, after=lambdae: play_next())
asyncdefplay_discord(ctx,url):
globalVC_Channel, que, qnamesifVC_ChannelisnotNone:
awaitctx.send("attempting to q")
try:
que.append(url)
qnames.append(url)
exceptExceptionase:
awaitctx.send(f"error adding to queue, {e}" )
returnawaitctx.send(f"added to queue! position: {len(que)}")
else:
FFMPEG_OPTIONS= {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5','options': '-vn -filter:a "volume=0.25"'}#optimised settings for ffmpeg for streamingsource=discord.PCMVolumeTransformer(FFmpegPCMAudio(source=url))
vc=awaitctx.author.voice.channel.connect(self_deaf=True)
VC_Channel=vcawaitctx.send(f"playing...")
vc.play(source, after=lambdae: play_next())
defplay_next():
globalVC_Channel, que, qnamesiflen(que) >0andVC_ChannelisnotNone:
url=que[0]
qnames.pop(0)
que.pop(0)
FFMPEG_OPTIONS= {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5','options': '-vn -filter:a "volume=0.25"'}#optimised settings for ffmpeg for streamingsource=FFmpegPCMAudio(source=url, executable="ffmpeg",**FFMPEG_OPTIONS)
VC_Channel.play(source, after=lambdae: play_next())
@bot.command()asyncdefplay(ctx, url: str):
globalVC_Channel, que, qnamesifnoturl.find("https://www.youtube.com/watch?v=") ==-1:
awaitctx.send("yt video detected")
awaityt_play(ctx, url)
elifnoturl.find("discord") ==-1:
awaitctx.send("discord link detected")
awaitplay_discord(ctx,url)
elifnoturl.find("https://soundcloud.com/") ==-1:
awaitctx.send("soundcloud link detected")
awaitsc_play(ctx, url)
else:
awaitctx.send("link not supported")
@bot.command()asyncdefstop(ctx):
globalVC_Channelifctx.channel.id!=1169505345991872573:
returnifVC_ChannelisnotNone:
VC_Channel.stop()
awaitVC_Channel.disconnect()
VC_Channel=Noneawaitctx.send("https://media.discordapp.net/attachments/1003026559147446305/1413913241582571670/give_us_space_pricks_the_humblle_brahman.gif?ex=68be5192&is=68bd0012&hm=9a1fb0ecefe7faa069442f116d6a0bd8d63ff6356ae7df9902e8613ea164722b&=&width=500&height=281")
@bot.command()asyncdefpause(ctx):
globalVC_Channelifctx.channel.id!=1169505345991872573:
returnifVC_ChannelisnotNone:
ifVC_Channel.is_playing():
VC_Channel.pause()
awaitctx.reply(":pause_button:")
else:
awaitctx.reply("not playing anything!")
@bot.command()asyncdefnext(ctx):
globalVC_Channel, que, qnamesifctx.channel.id!=1169505345991872573:
returnifVC_ChannelisnotNone:
iflen(que) ==0:
awaitctx.send("queue empty!")
returnVC_Channel.stop()
awaitctx.send(":track_next:")
@bot.command()asyncdefresume(ctx):
globalVC_Channelifctx.channel.id!=1169505345991872573:
returnifVC_ChannelisnotNone:
ifVC_Channel.is_paused():
VC_Channel.resume()
awaitctx.reply(":arrow_forward:")
else:
awaitctx.reply("not paused!")
@bot.command()asyncdefq(ctx):
globalque, qnamesifctx.channel.id!=1169505345991872573:
returniflen(que) ==0:
awaitctx.send("queue empty!")
returnmsg="Current Queue:\n"foriinrange(len(qnames)):
msg+=f"{i+1}. {qnames[i]}\n"awaitctx.send(msg)
bot.run('token')
this is my code,
the bot sends the file on discord, and the audio plays so its not corrupted or anything either.
but when the script tries to play it, it instantly terminates the player.
Heres the console:
2025-09-07 17:42:19 INFO discord.client logging in using static token
2025-09-07 17:42:23 INFO discord.gateway Shard ID None has connected to Gateway (Session ID: 570f989f95be0b72e2130a59efaf17e9).
2025-09-07 17:42:28 INFO discord.voice_state Connecting to voice...
2025-09-07 17:42:28 INFO discord.voice_state Starting voice handshake... (connection attempt 1)
2025-09-07 17:42:28 INFO discord.voice_state Voice handshake complete. Endpoint found: c-ams06-72c5011c.discord.media:8443
2025-09-07 17:42:30 INFO discord.voice_state Voice connection complete.
2025-09-07 17:42:31 INFO discord.player ffmpeg process 12548 successfully terminated with return code of 4294967295.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
this is my code,
the bot sends the file on discord, and the audio plays so its not corrupted or anything either.
but when the script tries to play it, it instantly terminates the player.
Heres the console:
Beta Was this translation helpful? Give feedback.
All reactions