Skip to main content

A powerful and robust Python library built from the ground up for interacting with Lavalink.

Project description

https://raw.githubusercontent.com/Aspect1103/Lavapy/master/logo.png https://img.shields.io/pypi/pyversions/Lavapy https://img.shields.io/pypi/v/Lavapy https://readthedocs.org/projects/lavapy/badge/?version=latest https://img.shields.io/github/license/Aspect1103/Lavapy https://img.shields.io/lgtm/grade/python/g/Aspect1103/Lavapy.svg?logo=lgtm&logoWidth=18

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 discord.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")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Lavapy-1.3.2.tar.gz (23.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

Lavapy-1.3.2-py3-none-any.whl (37.6 kB view details)

Uploaded Python 3

File details

Details for the file Lavapy-1.3.2.tar.gz.

File metadata

  • Download URL: Lavapy-1.3.2.tar.gz
  • Upload date:
  • Size: 23.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for Lavapy-1.3.2.tar.gz
Algorithm Hash digest
SHA256 d115acac47769e3fc194666e5dedbb8eca73830c8b61f5a83105ad0af50b2ee2
MD5 ef15c2cb9157ccb7ed02cf961bf2f064
BLAKE2b-256 c92b2dfb64589a4e1bbbf4128373ce90aea9ad61542dd08af9e8f48d5a2af471

See more details on using hashes here.

File details

Details for the file Lavapy-1.3.2-py3-none-any.whl.

File metadata

  • Download URL: Lavapy-1.3.2-py3-none-any.whl
  • Upload date:
  • Size: 37.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for Lavapy-1.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 cfd33d3ef2b5bc40ce8be05afabf18fbf0b920a20c572ae1e4975e45d8ad6934
MD5 ac6520c17dbd52560c25e69ce579c5ae
BLAKE2b-256 5a198628069091b408b93d8c3ca3b3193c7cac30bddb4862606b0f2a1aafe8ed

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page