A powerful and robust Python library built from the ground up for interacting with Lavalink.
Project description
A powerful and robust Python library built from the ground up for interacting with Lavalink.
Installation
Lavapy requires Python 3.8 or higher
To install Lavapy, use one of the commands below:
# Windows
py -3.8 -m pip install -U lavapy
# Linux/macOS
python3.8 -m pip install -U lavapy
Then you need to setup the Lavalink server. For more details visit the faq.
Now all of that is done, you can start using Lavapy.
Usage
A simple and easy example to connect to a voice channel and play a Youtube song based on a given search query.
from nextcord.ext import commands
import lavapy
bot = commands.Bot(command_prefix="!")
async def initialiseNodes():
"""
Wait until the bot is ready then create a Lavapy node
"""
await bot.wait_until_ready()
await lavapy.NodePool.createNode(client=bot,
host="0.0.0.0",
port=2333,
password="LAVALINK_PASSWORD")
@bot.command()
async def play(ctx: commands.Context, *query) -> None:
"""
Play a Youtube song from a given search query.
If the bot is not connected, connect it to the user's voice channel. For this
to work, the user must be connected to a voice channel
"""
if not ctx.voice_client:
# Bot is not connected to a voice channel
try:
player: lavapy.Player = await ctx.author.voice.channel.connect(cls=lavapy.Player)
except AttributeError:
# User is not connected to a voice channel
await ctx.channel.send("You must be connected to a voice channel")
return
else:
# Bot is connected to a voice channel
player: lavapy.Player = ctx.voice_client
# Get tracks based on the given search query
track = await lavapy.YoutubeTrack.search(" ".join(query), player.node)
await player.play(track)
bot.loop.create_task(initialiseNodes())
bot.run("BOT_TOKEN")
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
nextlava-1.3.0.tar.gz
(24.5 kB
view details)
Built Distribution
nextlava-1.3.0-py3-none-any.whl
(37.4 kB
view details)
File details
Details for the file nextlava-1.3.0.tar.gz
.
File metadata
- Download URL: nextlava-1.3.0.tar.gz
- Upload date:
- Size: 24.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/3.10.1 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7500115bbf4873f898d606c08a576c9251213c45f8dbdad93c70528094193ce9 |
|
MD5 | f5cf59548e5d3b1c0016102daf475523 |
|
BLAKE2b-256 | c5697af6fc91d19843d6fccc4f56ae3e11f77e2df317dbc711b2427348ec28f9 |
File details
Details for the file nextlava-1.3.0-py3-none-any.whl
.
File metadata
- Download URL: nextlava-1.3.0-py3-none-any.whl
- Upload date:
- Size: 37.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/3.10.1 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2f3992ab1c87bfc1331f0c44c61ba58321e93c2309511f587d4de9a2022a3dc |
|
MD5 | 52eb762c1a925937790566111fd16828 |
|
BLAKE2b-256 | 01f90e81458e5d551b6a1039d09d9aec2ba84f6ca41e2a3b8c8906d8b6b23a54 |