diff --git a/.vscode/PythonImportHelper-v2-Completion.json b/.vscode/PythonImportHelper-v2-Completion.json index 38a5703..1ef93ed 100644 --- a/.vscode/PythonImportHelper-v2-Completion.json +++ b/.vscode/PythonImportHelper-v2-Completion.json @@ -47,6 +47,14 @@ "detail": "discord.ext", "documentation": {} }, + { + "label": "commands", + "importPath": "discord.ext", + "description": "discord.ext", + "isExtraImport": true, + "detail": "discord.ext", + "documentation": {} + }, { "label": "random", "kind": 6, @@ -101,6 +109,15 @@ "detail": "psutil", "documentation": {} }, + { + "label": "wavelink", + "kind": 6, + "isExtraImport": true, + "importPath": "wavelink", + "description": "wavelink", + "detail": "wavelink", + "documentation": {} + }, { "label": "load_dotenv", "importPath": "dotenv", @@ -181,6 +198,15 @@ "detail": "cogs.sysinfo", "documentation": {} }, + { + "label": "Music", + "kind": 6, + "importPath": "wavelink.music", + "description": "wavelink.music", + "peekOfCode": "class Music(commands.Cog):\n def __init__(self, bot):\n self.bot = bot\n @commands.Cog.listener()\n async def on_ready(self):\n node = wavelink.Node(uri='http://127.0.0.1:2333', password='yuukabot')\n await wavelink.Pool.connect(nodes=[node], client=self.bot)\n print('✅ Wavelink connected to Lavalink')\n @commands.command()\n async def play(self, ctx, *, query: str):", + "detail": "wavelink.music", + "documentation": {} + }, { "label": "intents", "kind": 5, diff --git a/main.py b/main.py index ddb4775..abb1713 100644 --- a/main.py +++ b/main.py @@ -23,6 +23,7 @@ async def main(): await bot.load_extension('cogs.gifs') await bot.load_extension('cogs.copypasta') await bot.load_extension('cogs.sysinfo') + await bot.load_extension('cogs.wavelink.music') await bot.start(os.getenv('DISCORD_TOKEN')) logging.basicConfig(level=logging.INFO) diff --git a/wavelink/__init__.py b/wavelink/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/wavelink/music.py b/wavelink/music.py new file mode 100644 index 0000000..d605b08 --- /dev/null +++ b/wavelink/music.py @@ -0,0 +1,54 @@ +import wavelink +import discord +from discord.ext import commands + + +class Music(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @commands.Cog.listener() + async def on_ready(self): + node = wavelink.Node(uri='http://127.0.0.1:2333', password='yuukabot') + await wavelink.Pool.connect(nodes=[node], client=self.bot) + print('✅ Wavelink connected to Lavalink') + + @commands.command() + async def play(self, ctx, *, query: str): + if not ctx.author.voice: + return await ctx.reply('you need to be in a voice channel!') + + if not ctx.voice_client: + vc: wavelink.Player = await ctx.author.voice.channel.connect(cls=wavelink.Player) + else: + vc: wavelink.Player = ctx.voice_client + + tracks = await wavelink.Playable.search(query) + if not tracks: + return await ctx.reply('nothing found!') + + track = tracks[0] + await vc.play(track) + await ctx.reply(f'▶️ now playing: {track.title}') + + @commands.command() + async def stop(self, ctx): + if ctx.voice_client: + await ctx.voice_client.disconnect() + await ctx.reply('⏹️ stopped!') + + @commands.command() + async def skip(self, ctx): + if ctx.voice_client: + await ctx.voice_client.skip() + await ctx.reply('⏭️ skipped!') + + @commands.command() + async def pause(self, ctx): + if ctx.voice_client: + await ctx.voice_client.pause(not ctx.voice_client.paused) + await ctx.reply('⏸️ toggled pause!') + + +async def setup(bot): + await bot.add_cog(Music(bot)) \ No newline at end of file