1
0
Fork 0
mirror of https://gitlab.jonasled.de/jonasled/discordbot synced 2024-09-27 21:18:52 +02:00

fixed music bot

This commit is contained in:
Jonas Leder 2020-12-02 12:45:21 +01:00
parent 3788382e82
commit dafa9bcf1f

15
bot.py
View file

@ -8,7 +8,7 @@ from config import *
from requests import get from requests import get
from json import loads from json import loads
from os import remove, listdir from os import remove, listdir
from youtube_dl import YoutubeDL from youtube_dlc import YoutubeDL
from time import time from time import time
from asyncio import sleep from asyncio import sleep
from io import BytesIO from io import BytesIO
@ -738,6 +738,7 @@ async def checkForNextSong(): # background task, that runs every second and che
try: try:
if (player != None) and not player.is_playing() and ( if (player != None) and not player.is_playing() and (
len(playerQue) > 0): # check if the player is active and the song ended len(playerQue) > 0): # check if the player is active and the song ended
print("song ended")
if (playing): # check if the player played previously if (playing): # check if the player played previously
print("clear last") print("clear last")
playerQue.remove(playerQue[0]) # remove the first entry from the que and the first title playerQue.remove(playerQue[0]) # remove the first entry from the que and the first title
@ -755,12 +756,14 @@ async def checkForNextSong(): # background task, that runs every second and che
if 'entries' in data: if 'entries' in data:
# take first item from a playlist # take first item from a playlist
data = data['entries'][0] data = data['entries'][0]
for format in data["formats"]:
if(format["format_id"] == "140"):
try:
filename = data["formats"][0]["manifest_url"]
except:
filename = data["formats"][0]["url"]
try: print("start playback: " + filename)
filename = data["formats"][0]["manifest_url"]
except:
filename = data["formats"][0]["url"]
audioPlayer = discord.PCMVolumeTransformer(discord.FFmpegPCMAudio(filename, **{ audioPlayer = discord.PCMVolumeTransformer(discord.FFmpegPCMAudio(filename, **{
'options': '-vn'})) # convert the audio player to a volume audio player 'options': '-vn'})) # convert the audio player to a volume audio player
player.play(audioPlayer) player.play(audioPlayer)