added minimal play feature, ready for expantion

This commit is contained in:
2023-05-24 10:03:45 +01:00
parent dd2ee80269
commit 564d8f053d
3 changed files with 84 additions and 1 deletions

View File

@@ -2,10 +2,13 @@ import discord
from discord.ext import commands
from discord.ext.commands.context import Context
import cogs.music.util as util
import cogs.music.queue as queue
import datetime
import pytz
import yt_dlp
from cogs.music.help import music_help
class music(commands.Cog):
@@ -38,4 +41,33 @@ class music(commands.Cog):
await util.join_vc(ctx)
await ctx.message.add_reaction('👍')
@commands.command(
help="Leaves the voice chat if the bot is present",
aliases=['disconnect'])
async def leave(self, ctx: Context):
await util.leave_vc(ctx)
await ctx.message.add_reaction('👍')
@commands.command(
help="Queues a song into the bot",
aliases=['p', 'qeue', 'q'])
async def play(self, ctx: Context, *, url=None):
if url is None:
raise commands.CommandError("Must provide a link or search query")
await util.join_vc(ctx)
ydl_opts = {
'format': 'bestaudio/best',
'outtmpl': 'downloads/%(title)s.%(ext)s',
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(url, download=True)
filename = ydl.prepare_filename(info)
ctx.voice_client.play(discord.FFmpegPCMAudio(executable="ffmpeg", source=filename), after=self.test)
def test(self, error):
print("Hello")