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
Been trying to make a private bot to play song from YouTube, and the song stop in the last 10-15s of the entire duration. Doesn't matter the length of the clip.
this is the error or rather conclusion after the song stops playing abruptly-
"2023-08-01 21:17:57 INFO discord.player ffmpeg process 20732 successfully terminated with return code of 0."
guessing this is a problem with how the discord.FFmpegPCMAudio handles the stream of audio as ffmpeg with code 0 means it played all the bits it received or I could be wrong here.
or its a YouTube thing that they continuously change the actual file links to stop 3rd party services playing off their platform.
I dunno at this point what am I doing wrong here.
code:
importdatetimeimportntplibimportdiscordimportasyncioimportyt_dlpydl_opts= {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
}
fromdiscordimportapp_commandsfromdiscord.extimportcommandsfromdotenvimportdotenv_valuesimportwarningswarnings.filterwarnings("ignore", category=RuntimeWarning)
try:
temp_time=ntplib.NTPClient()
response=temp_time.request('pool.ntp.org')
x=datetime.datetime.fromtimestamp(response.tx_time)
print('Internet date and time:',x.strftime("%d/%m/%Y %I:%M:%S %p"))
except:
print("Date Time server not Available")
intents=discord.Intents.all()
intents.voice_states=Trueclient=commands.Bot(command_prefix='+', activity=discord.Game(name="/help"), intents=intents)
song_queue= {}
@client.eventasyncdefon_ready():
print(f'{client.user} has connected to Discord Server\n')
forguildinclient.guilds:
song_queue[guild.id] = []
print("Server Name:",guild.name," Server ID:",guild.id,'\n')
#print(song_queue)try:
synced=awaitclient.tree.sync()
print(f"Synced {len(synced)} Commands")
exceptExceptionase:
print(e)
@client.eventasyncdefon_guild_join(guild):
song_queue[guild] = []
#print(song_queue)@client.eventasyncdefon_guild_remove(guild):
song_queue.pop(guild)
#print(song_queue)@client.tree.command(name="play", description="Play Music")@app_commands.describe(link="Enter Youtube Link")asyncdefplay(interaction: discord.Interaction, link:str):
ifinteraction.user.voiceisNone:
returnawaitinteraction.response.send_message(f"You're not in a vc, cant play", ephemeral=True)
elifinteraction.user.voice.channelisnotNoneandinteraction.guild.voice_clientisnotNoneandinteraction.user.voice.channel!=interaction.guild.voice_client.channel:
returnawaitinteraction.response.send_message(f"Occupied, cant join your vc", ephemeral=True)
else:
print(interaction)
channel=interaction.user.voice.channelvc=awaitchannel.connect()
ifvc.is_playing() isFalse:
awaitinteraction.response.send_message(f"Playing : {link}", ephemeral=False)
loop=asyncio.get_event_loop()
filename=awaitloop.run_in_executor(None, lambda: yt_dlp.YoutubeDL(ydl_opts).extract_info(link, download=False))
print(filename)
returnvc.play(discord.FFmpegPCMAudio(filename['url']))
client.run(dotenv_values("token.env")["BOT_TOKEN"])
ps - I've wrote very bare bones code to just get test whether the song plays or not. pls Ignore messy coding :p
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
-
Been trying to make a private bot to play song from YouTube, and the song stop in the last 10-15s of the entire duration. Doesn't matter the length of the clip.
this is the error or rather conclusion after the song stops playing abruptly-
"2023-08-01 21:17:57 INFO discord.player ffmpeg process 20732 successfully terminated with return code of 0."
guessing this is a problem with how the discord.FFmpegPCMAudio handles the stream of audio as ffmpeg with code 0 means it played all the bits it received or I could be wrong here.
or its a YouTube thing that they continuously change the actual file links to stop 3rd party services playing off their platform.
I dunno at this point what am I doing wrong here.
code:
ps - I've wrote very bare bones code to just get test whether the song plays or not. pls Ignore messy coding :p
Bot.txt
Beta Was this translation helpful? Give feedback.
All reactions