Skip to content

Commit

Permalink
Update to lavalink.py v5
Browse files Browse the repository at this point in the history
Adds support for lavalink v4 API.
Also allow empty status.
  • Loading branch information
Ev-1 committed Mar 9, 2024
1 parent 7884b15 commit f379e09
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
8 changes: 5 additions & 3 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@ async def on_ready(self):
self.logger.debug("Bot Ready")

self.session = aiohttp.ClientSession(loop=self.loop)
await self.change_presence(activity=discord.Game(type=0,
name=conf["bot"]["playing status"]),
status=discord.Status.online)

if presence := conf["bot"]["playing status"]:
await self.change_presence(activity=discord.Game(type=0,
name=presence),
status=discord.Status.online)

def run(self):
try:
Expand Down
2 changes: 1 addition & 1 deletion musicbot/cogs/music/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
TrackStartEvent,
TrackStuckEvent,
)
from lavalink.models import AudioTrack
from lavalink import AudioTrack

from bs4 import BeautifulSoup

Expand Down
2 changes: 1 addition & 1 deletion musicbot/utils/mixplayer/mixqueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from random import shuffle
from typing import Generic, Iterable, Iterator, List, Optional, Tuple, TypeVar

from lavalink.models import AudioTrack
from lavalink import AudioTrack

# Would like to ensure the T has a "requester" attribute, but don't know if that is possible
T = TypeVar('T', bound=AudioTrack)
Expand Down
11 changes: 6 additions & 5 deletions musicbot/utils/mixplayer/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ async def play(self, track: Optional[AudioTrack] = None, start_time: int = 0):
await self.bassboost(False)
await self.nightcoreify(False)
await self.stop()
await self.node._dispatch_event(QueueEndEvent(self))
await self.client._dispatch_event(QueueEndEvent(self))
return
else:
# At this point track will not be None, as the queue is not empty
Expand All @@ -133,9 +133,9 @@ async def play(self, track: Optional[AudioTrack] = None, start_time: int = 0):
if track is None or track.track is None:
# Ignore, if the queue was empty we would have dispatched the event already
return
await self.node._send(op='play', guildId=str(self.guild_id),
track=track.track, startTime=start_time)
await self.node._dispatch_event(TrackStartEvent(self, track))
await self.play_track(track, start_time)

await self.client._dispatch_event(TrackStartEvent(self, track))
self.logger.info(f"Playing track: {track.title}")

async def skip(self, pos: int = 0):
Expand All @@ -149,7 +149,8 @@ async def skip(self, pos: int = 0):

async def stop(self):
"""Stops the player."""
await self.node._send(op='stop', guildId=str(self.guild_id))
# await self.node._send(op='stop', guildId=str(self.guild_id))
await super().stop()
self.current = None
self.queue.enable_looping(False)
self.logger.info("Music player stopped, clearing current track and stopping looping")
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
discord.py == 2.3.*
lavalink == 4.0.*
lavalink == 5.3.*
asyncio
pyyaml
BeautifulSoup4
Expand Down

0 comments on commit f379e09

Please sign in to comment.