Skip to main content

Prerequisites

Make sure you have a running lavalink server.

Installation

pip install git+https://github.com/KaasToast/Pisslink.py

Basic example

import discord
import pisslink
import re

from discord.commands import slash_command
from discord.ext import commands

YOUTUBE_REGEX = re.compile(r'^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w\-]+\?v=|embed\/|v\/)?)([\w\-]+)(\S+)?$')

class Client(discord.Bot):

    def __init__(self):
        super().__init__()

class Music(commands.Cog):

    def __init__(self, client):
        self.client = client
        self.client.loop.create_task(self.node())

    async def node(self):
        await self.client.wait_until_ready()
        await pisslink.NodePool.create_node(
            client = self.client,
            host = '127.0.0.1',
            port = 2333,
            password = 'youshallnotpass'
        )

    @slash_command()
    async def play(self, ctx, query):
        '''Play a song from youtube.'''
        player = ctx.voice_client
        await ctx.defer()
        if not player: # try to connect to the voice channel
            if not ctx.author.voice:
                return await ctx.respond('You are not connected to a voice channel.')
            else:
                try:
                    channel = ctx.author.voice.channel
                    await channel.connect(cls=pisslink.Player())
                    player = ctx.voice_client
                except discord.Forbidden:
                    return await ctx.respond('I do not have access to this channel.')
        if not ctx.author.voice or player.channel != ctx.author.voice.channel: # check if author is in same channel as the bot
            await ctx.respond('You must be in the same channel as the bot.')
        else:
            if YOUTUBE_REGEX.match(query): # check if query is url.
                track = await pisslink.PisslinkTrack.get(query, return_first=True)
            else: # query is not a url
                track = await pisslink.PisslinkTrack.search(query, return_first=True)
            if not track: # check if track was found
                await ctx.respond('Song not found.')
            else: # play the track
                await player.play(track)
                await ctx.respond(f'Playing {track.title}.')

client = Client()
client.add_cog(Music(client))
client.run('TOKEN')

For advanced usage see advanced.py

Release files for pisslink 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pisslink 1.0.2
File Size Uploaded
pisslink-1.0.2.tar.gz 10.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pisslink 1.0.2
File Interpreter ABI Platform
pisslink-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 23.3 kB

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page