interactions-lavalink
Installation
Download ext via pip install --upgrade interactions-lavalink
Configuring own lavalink server
- Download Java SE if you don't have it
- Download lavalink from this repo
- Configure
application.ymlfile like here - Run lavalink server via
java -jar Lavalink.jarin same folder withapplication.ymlfile.
Usage
Create bot like example and run it.
Main file:
from interactions import Client
# Creating bot variable
client = Client()
# Loading your extension
client.load("exts.music")
# Starting bot
client.start("TOKEN")
Extension file: exts/music.py
from interactions import Extension, SlashContext, listen, slash_command, slash_option
from interactions_lavalink import Lavalink
from interactions_lavalink.events import TrackStart
class Music(Extension):
def __init__(self, client):
self.client = client
self.lavalink: Lavalink | None = None
@listen()
async def on_startup(self):
# Initializing lavalink instance on bot startup
self.lavalink: Lavalink = Lavalink(self.client)
# Connecting to local lavalink server
self.lavalink.add_node("127.0.0.1", 43421, "your_password", "eu")
@listen()
async def on_track_start(self, event: TrackStart):
print("Track started", event.track.title)
@slash_command()
@slash_option("query", "The search query or url", opt_type=3, required=True)
async def play(self, ctx: SlashContext, query: str):
await ctx.defer()
# Getting user's voice state
voice_state = ctx.author.voice
if not voice_state or not voice_state.channel:
return await ctx.send("You're not connected to the voice channel!")
# Connecting to voice channel and getting player instance
player = await self.lavalink.connect(voice_state.guild.id, voice_state.channel.id)
# Getting tracks from youtube
tracks = await player.search_youtube(query)
track = tracks[0]
# Adding track to the queue
player.add(requester=int(ctx.author.id), track=track)
# Check if player is already playing
if player.is_playing:
return await ctx.send(f"Added to queue: `{track.title}`")
# Starting playing track
await player.play()
await ctx.send(f"Now playing: `{track.title}`")
@slash_command()
async def leave(self, ctx: SlashContext):
# Disconnecting from voice channel
await self.lavalink.disconnect(ctx.guild.id)
await ctx.send("Disconnected", ephemeral=True)
Events
To listen lavalink event you have to use @listen decorator.
from interactions import Extension, listen
from interactions_lavalink import TrackStart, TrackEnd, QueueEnd
class MusicExt(Extension):
... # Some your cool music commands
# There are many useful events for you. You can use other events if you want it.
@listen()
async def on_track_start(self, event: TrackStart):
"""Fires when track starts"""
print(f"Track {event.track.title} started")
@listen()
async def on_track_end(self, event: TrackEnd):
"""Fires when track ends"""
@listen()
async def on_queue_end(self, event: QueueEnd):
"""Fires when queue ends"""
More events you could find in the lavalink.py documentation
Documentation
Release files for interactions-lavalink 3.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| interactions_lavalink-3.0.0.tar.gz | 17.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| interactions_lavalink-3.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 35.2 kB
Release files / interactions_lavalink-3.0.0.tar.gz
| Download URL | interactions_lavalink-3.0.0.tar.gz |
|---|---|
| Size | 17.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0de870d9c076c6370d53184c792fb52d4b86fd615a4cbafdc0d1f379370c5547
|
|
BLAKE2b-256 checksum How to use checksums |
a8082ae672de8ef1329c02611b8c53c10ad07cecae080f428ffb6b681292b90a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.9.19
|
Release files / interactions_lavalink-3.0.0-py3-none-any.whl
| Download URL | interactions_lavalink-3.0.0-py3-none-any.whl |
|---|---|
| Size | 17.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
901f3f9321d9b54e2cdcdc66e5ca715ebf804df8bca110a1eed71be6cbd8efdf
|
|
BLAKE2b-256 checksum How to use checksums |
e57f99f3e4925e9390a725d4cbe5e49c1d318e44910c54049cbcd0165ca5bd0e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.9.19
|