Skip to main content

Lavalink and voice support for interactions.py

Project description

interactions-lavalink

Installation

  1. Download Java if you don't have it
  2. Download lavalink from this repo
  3. Configure application.yml file like here
  4. Download ext via pip install interactions-lavalink

Usage

Run lavalink via java -jar Lavalink.jar in same folder with application.yml file. Create bot like example and run it.

import interactions
from interactions.ext.lavalink import VoiceState, VoiceClient

client = VoiceClient(...)

@client.event()
async def on_start():
    client.lavalink_client.add_node("127.0.0.1", 43421, "your_password", "eu")  # Copy host, port and password from `application.yml`

@client.event()
async def on_voice_state_update(before: VoiceState, after: VoiceState):
    ...

@client.command()
@interactions.option()
async def play(ctx: interactions.CommandContext, query: str):
    await ctx.defer()
    # NOTE: ctx.author.voice can be None if you runned a bot after joining the voice channel
    player = await self.client.connect(ctx.author.voice.guild_id, ctx.author.voice.channel_id)

    results = await player.node.get_tracks(f"ytsearch:{query}")
    track = AudioTrack(results["tracks"][0], int(ctx.author.id))
    player.add(requester=int(ctx.author.id), track=track)
    await player.play()

    await ctx.send(f"Now playing: `{track.title}`")

client.start()

Example with using Extension here

New methods/properties for interactions.py library

Member.voice - returns current member's VoiceState. It can be None if not cached. Channel.voice_states - returns a list of voice states of the voice channel. Can be empty if not cached. Guild.voice_states - returns a list of guild voice states. Can be empty if not cached.

Documentation

lavalink.py documentation lavalink.py repository

Credits

Thanks EdVraz for VoiceState from voice ext

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

interactions-lavalink-0.0.2.tar.gz (19.4 kB view details)

Uploaded Source

Built Distribution

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

interactions_lavalink-0.0.2-py3-none-any.whl (19.8 kB view details)

Uploaded Python 3

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