generated from Damego/python-pypi-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
1,154 additions
and
296 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,4 +132,3 @@ dmypy.json | |
|
||
logs/* | ||
Lavalink.jar | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
include requirements.txt | ||
recursive-include interactions_lavalink * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
from interactions import Intents | ||
from interactions.ext.lavalink import VoiceClient | ||
from interactions import Client | ||
|
||
client = VoiceClient("TOKEN", intents=Intents.DEFAULT) | ||
client = Client() | ||
|
||
client.load("exts.music") | ||
|
||
client.start() | ||
client.load_extension("exts.music") | ||
client.start("TOKEN") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,55 @@ | ||
from interactions import ( | ||
CommandContext, | ||
Extension, | ||
VoiceState, | ||
extension_command, | ||
extension_listener, | ||
option, | ||
) | ||
from interactions.ext.lavalink import Lavalink | ||
from interactions import Extension, SlashContext, listen, slash_command, slash_option | ||
|
||
from interactions_lavalink import Lavalink | ||
from interactions_lavalink.events import TrackStart | ||
|
||
|
||
class Music(Extension): | ||
def __init__(self, client): | ||
self.client = client | ||
self.lavalink: Lavalink = None | ||
self.lavalink: Lavalink | None = None | ||
|
||
@extension_listener() | ||
async def on_start(self): | ||
# Initialize lavalink instance | ||
@listen() | ||
async def on_startup(self): | ||
# Initializing lavalink instance on bot startup | ||
self.lavalink: Lavalink = Lavalink(self.client) | ||
|
||
# Connect to lavalink server | ||
# Connecting to local lavalink server | ||
self.lavalink.add_node("127.0.0.1", 43421, "your_password", "eu") | ||
|
||
@extension_command() | ||
@option() | ||
async def play(self, ctx: CommandContext, query: str): | ||
@listen() | ||
async def on_track_start(self, event: TrackStart): | ||
print("Track started", event.track.title) | ||
|
||
@slash_command() | ||
@slash_option("query", "The search query or url", opt_type=3, required=True) | ||
async def play(self, ctx: SlashContext, query: str): | ||
await ctx.defer() | ||
|
||
# Getting user's voice state | ||
voice_state: VoiceState = ctx.author.voice_state | ||
if not voice_state or not voice_state.joined: | ||
voice_state = ctx.author.voice | ||
if not voice_state or not voice_state.channel: | ||
return await ctx.send("You're not connected to the voice channel!") | ||
|
||
# Connecting to voice channel and getting player instance | ||
player = await self.lavalink.connect(voice_state.guild_id, voice_state.channel_id) | ||
|
||
player = await self.lavalink.connect(voice_state.guild.id, voice_state.channel.id) | ||
# Getting tracks from youtube | ||
tracks = await player.search_youtube(query) | ||
# Selecting first founded track | ||
track = tracks[0] | ||
# Adding track to the queue | ||
player.add(requester=int(ctx.author.id), track=track) | ||
|
||
# Check if already playing | ||
# Check if player is already playing | ||
if player.is_playing: | ||
return await ctx.send(f"Added to queue: `{track.title}`") | ||
|
||
# Starting playing track | ||
await player.play() | ||
await ctx.send(f"Now playing: `{track.title}`") | ||
|
||
@extension_command() | ||
async def leave(self, ctx: CommandContext): | ||
# Disconnect from voice channel and remove player | ||
await self.lavalink.disconnect(ctx.guild_id) | ||
|
||
await ctx.send("Disconnected", ephemeral=True) | ||
|
||
@slash_command() | ||
async def leave(self, ctx: SlashContext): | ||
# Disconnecting from voice channel | ||
await self.lavalink.disconnect(ctx.guild.id) | ||
|
||
def setup(client): | ||
Music(client) | ||
await ctx.send("Disconnected", ephemeral=True) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.