devoxin / lavalink.py Goto Github PK
View Code? Open in Web Editor NEWA wrapper for Lavalink in Python, which aims to be powerful and intuitive.
Home Page: https://lavalink.readthedocs.io/
License: MIT License
A wrapper for Lavalink in Python, which aims to be powerful and intuitive.
Home Page: https://lavalink.readthedocs.io/
License: MIT License
bot join voice channel but music doesn't works
discord.py 2.0, ubuntu 18, last version of Lavalink and Lavalink.jar
It seems that raising an exception (any exception) in a lavalink.event
will stuck the event.
How to repro (with v2 or v3 example) :
elif isinstance(event, lavalink.Events.TrackEndEvent):
print("TrackEndEvent called")
raise Exception('This error will block the nexts TrackEndEvent')
You can try yourself to play some songs and see that the TrackEndEvent is stuck
On the readthedocs page for lavalink.py under the DefaultPlayer section the .repeat definitions states "Whether or not to continuously to play a track.". This sounds like DefaultPlayer.current will seek back to 0 when finished while this bool is True but in fact repeats the whole queue when the bool is True.
Spotted a typo: "Whether or not to continuously to play a track" under the DefaultPLayer.repeat section
DefaultPlayer.set_repeat(repeat:bool) is also missing from the documentation as far as ctrl+f / readthedocs search is concerned.
java.lang.UnsupportedClassVersionError: lavalink/server/info/AppInfo has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
I just downloaded the lastest version of Java and this is the error I get when running the java -jar command in terminal
Hey i am using lavalink V4 and i am getting this error
Ignoring exception in on_command_error
Traceback (most recent call last):
File "C:\Users\nirma\AppData\Roaming\Python\Python310\site-packages\disnake\client.py", line 515, in _run_event
await coro(*args, **kwargs)
File "C:\Users\nirma\Desktop\new-discord-bot\cogs\logs.py", line 147, in on_command_error
raise error
File "C:\Users\nirma\AppData\Roaming\Python\Python310\site-packages\disnake\ext\commands\core.py", line 169, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\nirma\Desktop\new-discord-bot\cogs\new_music.py", line 458, in play
track = ImageTrack(data=track, requester=ctx.author.id, image=await self.get_soundcloud_artwork(track["info"]["uri"]))
File "C:\Users\nirma\Desktop\new-discord-bot\cogs\new_music.py", line 20, in __init__
super().__init__(data, requester, **extra)
File "C:\Users\nirma\AppData\Roaming\Python\Python310\site-packages\lavalink\models.py", line 78, in __init__
info = data.get('info', data)
AttributeError: 'AudioTrack' object has no attribute 'get'
code
class ImageTrack(lavalink.models.AudioTrack):
def __init__(self, data: dict, requester: int, **extra):
super().__init__(data, requester, **extra)
self.image = extra['image']
On request song/play
Linux: ubuntu 18.04
Python: 3.6
Lavalink.py: 3.1.4
Lavalink Player: Build #1186
Thoughts out an error
UnicodeDecodeError
'utf-8' codec can't decode byte 0xed in position 19: invalid continuation byte
File: utils.py | @ decode_track at line: 68
title = reader.read_utf().decode(errors=decode_errors)
author = reader.read_utf().decode()
length = reader.read_long()
identifier = reader.read_utf().decode()
is_stream = reader.read_boolean()
uri = reader.read_utf().decode() if reader.read_boolean() else None
source = reader.read_utf().decode()
When playing some tracks, playback stops working. By "stops working" I mean the following:
The only solution is to restart the bot, or recreate the player
I would like to point out that a bot written in java(Lavalink-client) using the same server behaves normally
The systems where I checked it out: Windows 11(23H2), Debian 11, Ubuntu, Ubuntu server
Pyhon version: 3.11.2
Lavalink.py version: lates(5.3.0)
Lavalink version version: lates(4.0.4)
Step 1:
Step 2:
Step 3:
The bot should have played the first track.
After using the command to skip, it should have started playing the second track
The bot does not play the first track, and even after skipping a track this problem persists
I found a simple function to monitor requests and I used it to find out what was causing the behavior. As a result, I saw something unusual: *click*
Pay attention to "position". Unlike normal tracks, which are processed normally, the "position" value is frozen at 460. In case of skipping a track, this value does not change either
So when I send a voice_state event from d.py I should expect first a VOICE_STATE_UPDATE
and then a VOICE_SERVER_UPDATE
, but the catch is that only VOICE_STATE_UPDATE is received and the other one never comes.
This issue must be connected to lavalink not producing sound after a server region change.
I am running lavalink on a aws linux server and when I detach the screen and leave lavalink running after some time it randomly kills itself. The bot stills works and stays online but none of the music commands work at all after some time. This time can be between 10 minutes and 2 hours in which it kills itself.
I reattached the terminal and this is the error message in which I recieve.
etServer : {"op": "play", "guildId": "764284423969046539", "track": "QAAAngIAOU1hcmsgUm9uc29uIC0gVXB0b3duIEZ1bmsgKE9mZmljaWFsIFZpZGVvKSBmdC4gQnJ1bm8gTWFycwALTWFyayBSb25zb24AAAAAAAQimAALT1BmMFliWHFEbTAAAQAraHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g/dj1PUGYwWWJYcURtMAAHeW91dHViZQAAAAAAAAAA"}
2020-11-15 15:05:53.418 INFO 4535 --- [ XNIO-1 I/O-1] lavalink.server.io.SocketServer : {"op": "voiceUpdate", "guildId": "777254786310340659", "sessionId": "4d4f6bf286004ed6a80cbb9bb7753945", "event": {"token": "bb01d27cdf3f2e6f", "guild_id": "777254786310340659", "endpoint": "us-east1573.discord.media:443"}}
2020-11-15 15:06:12.221 INFO 4535 --- [ XNIO-1 task-14] l.server.player.AudioLoaderRestHandler : Got request to load for identifier "ytsearch:ncs limitless"
2020-11-15 15:06:12.720 INFO 4535 --- [ader-2-thread-1] lavalink.server.player.AudioLoader : Loaded playlist Search results for: ncs limitless
2020-11-15 15:06:18.834 INFO 4535 --- [ XNIO-1 I/O-1] lavalink.server.io.SocketServer : {"op": "play", "guildId": "777254786310340659", "track": "QAAAkQIAJkVsZWt0cm9ub21pYSAtIExpbWl0bGVzcyBbTkNTIFJlbGVhc2VdABFOb0NvcHlyaWdodFNvdW5kcwAAAAAAA70IAAtjTmN5M0o0eDYyTQABACtodHRwczovL3d3dy55b3V0dWJlLmNvbS93YXRjaD92PWNOY3kzSjR4NjJNAAd5b3V0dWJlAAAAAAAAAAA="}
2020-11-15 15:06:59.739 INFO 4535 --- [ XNIO-1 I/O-1] lavalink.server.io.SocketServer : {"op": "stop", "guildId": "777254786310340659"}
2020-11-15 15:07:18.993 INFO 4535 --- [ XNIO-1 I/O-1] lavalink.server.io.SocketServer : {"op": "stop", "guildId": "764284423969046539"}
Killed
There is no such thing as set_repeat. I need this to fully complete my bot music.py
Hi there,
When trying to load the cog it gives me this error:
- 'int' object has no attribute 'lavalink'
There's an issue here it seems with the deque
change re: the queue command. I quickly fixed it like this (in the music.py
example cog):
for i, track in enumerate(player.queue[start:end], start=start):
to:
for i, track in enumerate(list(player.queue)[start:end], start=start):
But I wouldn't say that changing the queue to a list is the most efficient way as it is doing two times the computation and for massive queues it could be slow, but I haven't noticed anything.
It fixes the slice error: - sequence index must be integer, not 'slice'
on running the queue command.
Also, I don't think shuffle is implemented correctly. It also causes various - pop() takes no arguments (1 given)
when trying to skip after turning shuffle on/off.
Please excuse any oversights; I'm not the most experienced in Python xD.
Task exception was never retrieved
future: <Task finished coro=<WebSocket.listen() done, defined at C:\Users\Zenrac\AppData\Local\Programs\Python\Python36-32\lib\site-packages\lavalink\WebSocket.py:92> exception=KeyError('position',)>
Traceback (most recent call last):
File "C:\Users\Zenrac\AppData\Local\Programs\Python\Python36-32\lib\site-packages\lavalink\WebSocket.py", line 130, in listen
await self._lavalink.update_state(data)
File "C:\Users\Zenrac\AppData\Local\Programs\Python\Python36-32\lib\site-packages\lavalink\Client.py", line 62, in update_state
p.position = data['state']['position']
KeyError: 'position'
It seems to happen since I've added an on_voice_state_update
event
I don't really know how to repro
Hello, i used the examplecode but then i get an nonetype error that i dont know how to solve:
Failed to load extension music.py
Traceback (most recent call last):
File "D:\Downloads\Python\python 3.8.7\lib\site-packages\discord\ext\commands\bot.py", line 618, in _load_from_module_spec
setup(self)
File "D:\my_python_projects\MongoDB Test\Cogs\music.py", line 175, in setup
bot.add_cog(Music(bot))
File "D:\my_python_projects\MongoDB Test\Cogs\music.py", line 22, in __init__
bot.lavalink = lavalink.Client(bot.user.id)
AttributeError: 'NoneType' object has no attribute 'id'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "D:/my_python_projects/MongoDB Test/mongosetup.py", line 145, in <module>
bot.load_extension(f"Cogs.{filename[:-3]}")
File "D:\Downloads\Python\python 3.8.7\lib\site-packages\discord\ext\commands\bot.py", line 678, in load_extension
self._load_from_module_spec(spec, name)
File "D:\Downloads\Python\python 3.8.7\lib\site-packages\discord\ext\commands\bot.py", line 623, in _load_from_module_spec
raise errors.ExtensionFailed(key, e) from e
discord.ext.commands.errors.ExtensionFailed: Extension 'Cogs.music' raised an error: AttributeError: 'NoneType' object has no attribute 'id'
wsproto 0.11.0 has requirement h11~=0.7.0, but you'll have h11 0.8.0 which is incompatible.
discord-py 1.0.0a1467+g6b75179 has requirement websockets<4.0,>=3.0, but you'll have websockets 5.0.1 which is incompatible.
This results in the bot not playing anything.
After we run the Lavalink.jar file, it establishes connection, after that whenever we play very first song, it plays nicely, but if we disconnect the bot after that and try to play another song, it doesnt work.
This is the where the jar file gets stuck at (in the terminal)
Loaded playlist Search results for: bekhayali
2020-11-13 12:23:28.786 INFO 34228 --- [ XNIO-1 I/O-4] lavalink.server.io.SocketServer : {"op": "play", "guildId": "760517589100527656", "track": "QAAAxgIAZEJla2hheWFsaSBGdWxsIFNvbmcgfCBLYWJpciBTaW5naCB8IFNoYWhpZCBLLEtpYXJhIEF8U2FuZGVlcCBSZWRkeSBWYW5nYSB8IFNhY2hldC1QYXJhbXBhcmEgfCBJcnNoYWQACFQtU2VyaWVzAAAAAAAFZtAAC1ZPTEtKSnZmQWJnAAEAK2h0dHBzOi8vd3d3LnlvdXR1YmUuY29tL3dhdGNoP3Y9Vk9MS0pKdmZBYmcAB3lvdXR1YmUAAAAAAAAAAA=="}
The current song will stop when it disconnects.
The previous song never stops. If we disconnect the bot from the vc, and reconnect it, the bots seems to be playing something but nothing is audible
Disconnected with code None and reason None
Unable to move players, no available nodes! Waiting for a node to become available.
When discord sends a reconnect payload and discord.py reconnects with a resume, the playback stops.
OS: Windows 10 & Centos 8.1 | Python 3.7.5 | Lavalink.py 3.1.0 |Lavalink latest (3.x)
Just playing any track or queue for a long time.
Turn on logging for discord.py to info so you can see gateway reconnects
The audio plays none-stop continuously without problems.
The audio stops whenever discord.py reconnects to the gateway or when discord sends a reconnect payload and causes the library to reconnect.
Rather than creating an all new function for something that is already built in to Python, maybe we should use isinstance()
Is it possible to make lavalink.py working on async? I changed every ctx.send etc. to async version, but now im getting this error:
results = await self.bot.lavalink.get_tracks(query)
File "C:\Users\Style\AppData\Local\Programs\Python\Python36-32\lib\site-packages\lavalink\Client.py", line 135, in get_tracks
return await res.json(content_type=None)
TypeError: json() got an unexpected keyword argument 'content_type'
As Guild.region
is removed. The example is needed to be fixed
OS: Linux
Python Version: 3.9.10
Lavalink.py: master
Lavalink Version: Latest (3.4)
In ensure_voice
method
async def ensure_voice(self, ctx):
""" This check ensures that the bot and command author are in the same voicechannel. """
player = self.bot.lavalink.player_manager.create(ctx.guild.id, endpoint=str(ctx.guild.region))
# Create returns a player if one exists, otherwise creates.
# This line is important because it ensures that a player always exists for a guild.
# Most people might consider this a waste of resources for guilds that aren't playing, but this is
# the easiest and simplest way of ensuring players are created.
# These are commands that require the bot to join a voicechannel (i.e. initiating playback).
# Commands such as volume/skip etc don't require the bot to be in a voicechannel so don't need listing here.
should_connect = ctx.command.name in ('play',)
if not ctx.author.voice or not ctx.author.voice.channel:
# Our cog_command_error handler catches this and sends it to the voicechannel.
# Exceptions allow us to "short-circuit" command invocation via checks so the
# execution state of the command goes no further.
raise commands.CommandInvokeError('Join a voicechannel first.')
if not player.is_connected:
if not should_connect:
raise commands.CommandInvokeError('Not connected.')
permissions = ctx.author.voice.channel.permissions_for(ctx.me)
if not permissions.connect or not permissions.speak: # Check user limit too?
raise commands.CommandInvokeError('I need the `CONNECT` and `SPEAK` permissions.')
player.store('channel', ctx.channel.id)
await ctx.author.voice.channel.connect(cls=LavalinkVoiceClient)
else:
if int(player.channel_id) != ctx.author.voice.channel.id:
raise commands.CommandInvokeError('You need to be in my voicechannel.')
Create a play_manager
Raised AttributeError: 'Guild' object has no attribute 'region'
Use VoiceChannel.rtc_region
attribute
Attempting to modify gains through set_gains(listoftuples)
crashes the player and forcefully makes the bot crash
tested with player.set_gain((0, 0.75), (1, 0.75), (2, 0.75), (3, 1), (5, 0.75))
Linux ARM64 Ubuntu 20.10, Lavalink 3.1.4, OpenJDK 15, Python 3.7
@commands.command(
name='bass',
brief='blow eardrums up'
)
@commands.check(djconfig)
async def bass(self, ctx, gain: int = 0):
"""increases the base."""
player = self.bot.lavalink.player_manager.get(ctx.guild.id)
if player:
if player.current is None:
await ctx.send('*⃣ | Bot is not playing any music.')
gain = max(min(1, gain), -0.25)
await player.set_gains((0, gain*.75),(1, gain*.75),(2, gain*.75),(3, gain),(4, gain*.75))
if gain:
await ctx.send(f'Bass set to {(gain+1)*100}%')
else:
await ctx.send('Bass set to 100%')
Put a gain of 1 for the gain input
Have the bot instantly disconnect from VC due to track decoding error
For the bass to increase and to not crash
Upon payload being received bot instantly leaves voicechat and prints this rather vague traceback
pls update the expamels for the music cog
Hi this ins't technicly a bug but the bot stops playing when ever i deafen it and is quit until the next song
No typing for DefaultPlayer.node. Would make intellisense a lot better when working with this library.
As I wrote in the title, its a fairly small thing but adding ': lavalink.Node' to the 'self.node = node' line in the BasePlayer class def would make intellisense a lot more useful when writing song search.... stuff.
Unrelated but thanks for all your work on the project! Came back to it after a couple years of building my bot with discord.js and its way nicer to use than my last library for Lavalink.
And filters! So glad there's filters now.
Pretty sure this is OS agnostic, but I'm on Ubuntu 22.10, python 3.10.7, Lavalink.py v4.0.4
Just drop into the default example in vscode with python intellisense enabled and hover over any instance of 'player.node.xyz'
any BasePlayer.node to be typed as (at least I assume this is right) lavalink.Node
No intellisense
when trying to install lavalink.py it tries to install a version of aiohttp which is unsupported by python 3.12
OS: Windows
Python version: 3.12
Lavalink.py: 5.1.0
run pip install lavalink
Hello, could you please mind updating the required aiohttp version requirements.
Lavalink current aiohttp version requirement: 3.6.0
Please update it to version 3.7.3
or later
@commands.command()
async def play(self, ctx, url):
song_there = os.path.isfile("song.mp3")
try:
if song_there:
os.remove("song.mp3")
except PermissionError:
await ctx.send("Wait for the current playing music to end or use the 'stop' command")
voiceChannel = discord.utils.get(ctx.guild.voice_channels)
await voiceChannel.connect()
voice = discord.utils.get(self.client.voice_clients, guild=ctx.guild)
ydl_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}]
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download([url])
for file in os.listdir("./"):
if file.endswith(".mp3"):
os.rename(file, "song.mp3")
voice.play(discord.FFmpegPCMAudio('song.mp3'))
**This is my current code I'm using to play music through my bot, but after some searching over the internet, I am unsure of how to have the bot queue music, because whenever I try to queue two songs, it'll say in the terminal that the bot is already connected to the voice channel. I couldn't get any other help so maybe I'd be able to get some here.. Thanks!**
I am currently trying to play music with a youtube link but it doesnt work. Any reason why? Idk
I want to install developer version... but in README.md
didn't show yet.
Every +- 30 seconds the following error keeps getting spammed into my console, even when its not playing music:
[NODE-eu-clerq-:80] Disconnected with code None and reason None
Unable to move players, no available nodes! Waiting for a node to become available.
Any way to supress/fix this error?
[Fixed]
Lavalink V3 supports volume value to be set up to 1000. What would be the best way to implement that feature without removing the support for lavalink v2.
My ideas:
on_ready
which makes a request to /loadtracks
and depending on the values determines if it's v2 or v3.Could lavalink.py have the two f strings reformatted?
When I try to play a song it returns
in create
raise NodeException('No available nodes!')
lavalink.exceptions.NodeException: No available nodes!
typo in link at https://lavalink.readthedocs.io/en/latest/quickstart.html
example cog refers to https://github.cmo/Devoxin/Lavalink.py/blob/master/examples/music.py
not relevant
goto https://lavalink.readthedocs.io/en/latest/quickstart.html and click at example cog
https://github.com/Devoxin/Lavalink.py/blob/master/examples/music.py
https://github.cmo/Devoxin/Lavalink.py/blob/master/examples/music.py
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.