Skip to main content

The modern Lavalink wrapper designed for Discord.py

Project description

Pomice

GPL Code style: black Discord Read the Docs

Pomice is a fully asynchronous Python library designed for communicating with Lavalink seamlessly within the discord.py library. It features 100% coverage of the Lavalink spec that can be accessed with easy-to-understand functions along with Spotify and Apple Music querying capabilities using built-in custom clients, making it easier to develop your next big music bot.

Quick Links

Install

To install the library, you need the lastest version of pip and minimum Python 3.8

Stable version

pip install pomice

Unstable version (this one gets more frequent changes)

pip install git+https://github.com/cloudwithax/pomice

Support And Documentation

The official documentation is here

You can join our support server here

Examples

In-depth examples are located in the examples folder

Here's a quick example:

import pomice
import discord
import re

from discord.ext import commands

URL_REG = re.compile(r'https?://(?:www\.)?.+')

class MyBot(commands.Bot):

    def __init__(self) -> None:
        super().__init__(command_prefix='!', activity=discord.Activity(type=discord.ActivityType.listening, name='to music!'))

        self.add_cog(Music(self))

    async def on_ready(self) -> None:
        print("I'm online!")
        await self.cogs["Music"].start_nodes()


class Music(commands.Cog):

    def __init__(self, bot) -> None:
        self.bot = bot

        self.pomice = pomice.NodePool()

    async def start_nodes(self):
        await self.pomice.create_node(bot=self.bot, host='127.0.0.1', port='3030',
                                     password='youshallnotpass', identifier='MAIN')
        print(f"Node is ready!")



    @commands.command(name='join', aliases=['connect'])
    async def join(self, ctx: commands.Context, *, channel: discord.TextChannel = None) -> None:

        if not channel:
            channel = getattr(ctx.author.voice, 'channel', None)
            if not channel:
                raise commands.CheckFailure('You must be in a voice channel to use this command'
                                            'without specifying the channel argument.')


        await ctx.author.voice.channel.connect(cls=pomice.Player)
        await ctx.send(f'Joined the voice channel `{channel}`')

    @commands.command(name='play')
    async def play(self, ctx, *, search: str) -> None:

        if not ctx.voice_client:
            await ctx.invoke(self.join)

        player = ctx.voice_client

        results = await player.get_tracks(query=f'{search}')

        if not results:
            raise commands.CommandError('No results were found for that search term.')

        if isinstance(results, pomice.Playlist):
            await player.play(track=results.tracks[0])
        else:
            await player.play(track=results[0])


bot = MyBot()
bot.run("token here")

FAQ

Why is it saying "Cannot connect to host"?

  • You need to have a Lavalink node setup before you can use this library. Download it here

What experience do I need?

  • This library requires that you have some experience with Python, asynchronous programming and the discord.py library.

Why is it saying "No module named pomice found"?

  • You need to install the package before you can use it

Contributors

  • Thanks to vveeps for implementing some features I wasn't able to do myself

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

pomice-2.4.0.tar.gz (48.8 kB view details)

Uploaded Source

Built Distribution

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

pomice-2.4.0-py3-none-any.whl (52.4 kB view details)

Uploaded Python 3

File details

Details for the file pomice-2.4.0.tar.gz.

File metadata

  • Download URL: pomice-2.4.0.tar.gz
  • Upload date:
  • Size: 48.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for pomice-2.4.0.tar.gz
Algorithm Hash digest
SHA256 e0474ac37a4e2ee7155003fecc1f30e06c206075c7473a2ed7f4e86c05205914
MD5 c8fb8b688c94241e7df6398702e3e99c
BLAKE2b-256 58707c44cc7ae09a17211fb609fb6e957a59ce6f8e969e6ae48f6ef2b6a1ea42

See more details on using hashes here.

File details

Details for the file pomice-2.4.0-py3-none-any.whl.

File metadata

  • Download URL: pomice-2.4.0-py3-none-any.whl
  • Upload date:
  • Size: 52.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for pomice-2.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5d62b4589b3fab4f2cf7ef28c172edc12296c1b86cbd6b61e70eeba028c6359d
MD5 33df39adb7664b70349b4b8caaa459bf
BLAKE2b-256 468bdcb8cb930cb8141238bb4ef53c5f9350d29d2616c01178b360f01433a0f8

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