-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmusic.py
More file actions
47 lines (39 loc) · 1.45 KB
/
music.py
File metadata and controls
47 lines (39 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import discord
from discord.ext import commands
class Music(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
self.last_play_request = {}
@commands.command()
async def play(self, ctx: commands.Context, url: str):
if "youtube.com" not in url and "youtu.be" not in url:
await ctx.send("Please provide a valid YouTube URL.")
return
msg = await ctx.send(
f"{ctx.author.mention}, press \u25B6\uFE0F to play this video in your voice channel."
)
await msg.add_reaction("\u25B6\uFE0F")
self.last_play_request = {
"message_id": msg.id,
"user_id": ctx.author.id,
"url": url,
"guild_id": ctx.guild.id,
}
@commands.command()
async def stop(self, ctx: commands.Context):
"""Stop playing audio, but stay connected to the voice channel."""
vc = ctx.voice_client
if vc and vc.is_playing():
vc.stop()
await ctx.send("Playback stopped.")
else:
await ctx.send("Nothing is playing right now.")
@commands.command()
async def leave(self, ctx: commands.Context):
if ctx.voice_client:
await ctx.voice_client.disconnect()
await ctx.send("Left the voice channel.")
else:
await ctx.send("I'm not in a voice channel.")
async def setup(bot: commands.Bot):
await bot.add_cog(Music(bot))