Minimalistic lavalink wrapper based on wavelink. Made for Pycord.
Project description
Pisslink.py
Minimalistic lavalink wrapper based on wavelink. Made for Pycord.
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
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
pisslink-1.0.2.tar.gz
(10.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
pisslink-1.0.2-py3-none-any.whl
(12.5 kB
view details)
File details
Details for the file pisslink-1.0.2.tar.gz.
File metadata
- Download URL: pisslink-1.0.2.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8efd9132ebb31d2c7da1fa765b96c41c3256b650ad973bf6b30c1632ad6249e9
|
|
| MD5 |
e687423183a5744879959f5506f95281
|
|
| BLAKE2b-256 |
d1bcdc13574b62ed81505ae169b082c9e123823d8d5c5876fc49ba1b30b61c17
|
File details
Details for the file pisslink-1.0.2-py3-none-any.whl.
File metadata
- Download URL: pisslink-1.0.2-py3-none-any.whl
- Upload date:
- Size: 12.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b790c6b40fb6be5c38e0713ec4badbf58ce98f1d60d8a686852be1d286f37169
|
|
| MD5 |
cd9d861dfc8604ddc832e005f00fe67f
|
|
| BLAKE2b-256 |
344c32b162431e7cec09e8497bd1610cb70a132d15b4a43d89de756daf419442
|