runabot/Christmas/Cogs/Commands_Music.py

58 lines
3.1 KiB
Python
Raw Normal View History

2023-12-02 06:03:50 +00:00
from discord.utils import basic_autocomplete
2023-12-02 10:42:36 +00:00
from discord import Member, SlashCommandGroup, Option, AutocompleteContext, Color
2023-11-26 04:27:34 +00:00
from discord.ext.commands import Cog, cooldown, BucketType, command, has_permissions, bot_has_permissions, Context, guild_only, bot_has_guild_permissions, check
2023-12-02 06:03:50 +00:00
import wavelink
2023-12-02 10:42:36 +00:00
import random
2023-12-02 06:03:50 +00:00
from Christmas.Database import database
2023-12-02 10:42:36 +00:00
from Christmas.UI.Embed import Music_Embed, ChristmasEmbed
from Christmas.config import ChristmasConfig
2023-12-02 06:03:50 +00:00
2023-11-26 04:27:34 +00:00
class CMusic(Cog):
def __init__(self, bot):
self.bot = bot
2023-12-02 10:42:36 +00:00
self.config = ChristmasConfig()
2023-11-26 04:27:34 +00:00
2023-12-02 06:03:50 +00:00
MUSIC = SlashCommandGroup(name="음악", description="음악을 재생합니다.")
#
2023-12-02 10:42:36 +00:00
@MUSIC.command(name="재생", description="LOFI 음악을 재생합니다.")
2023-12-02 06:03:50 +00:00
@cooldown(1, 10, BucketType.user)
@guild_only()
2023-12-02 10:42:36 +00:00
async def _play(self, ctx: Context):
if not await database.get_guild(ctx.guild.id): return await ctx.respond(embed=ChristmasEmbed(title="❌ 에러!", description="서버가 가입되어있지 않아요! 서버를 가입해주세요!", color=Color.red()),ephemeral=True)
await ctx.defer(ephemeral=True)
get_guild = await database.get_guild(ctx.guild.id)
if not get_guild["music"] == True: return await ctx.respond(embed=Music_Embed.music_notenable(), ephemeral=True)
2023-12-02 06:03:50 +00:00
if ctx.author.voice == None or ctx.author.voice.channel == None: return await ctx.respond(embed=Music_Embed.author_not_voice(), ephemeral=True)
player = None
2023-12-02 10:42:36 +00:00
node = wavelink.Pool.get_node()
if node.get_player(ctx.guild.id) == None:
2023-12-02 06:03:50 +00:00
player = await ctx.author.voice.channel.connect(cls=wavelink.Player)
2023-12-02 10:42:36 +00:00
else:
player = node.get_player(ctx.guild.id)
try:
query = await wavelink.Playable.search(random.choice(self.config.LOFI()), source=wavelink.TrackSource.YouTube)
await player.play(query[0])
await ctx.respond(embed=Music_Embed.music_play())
except Exception as e:
print(e)
@MUSIC.command(name="정지", description="음악을 정지합니다.")
@cooldown(1, 10, BucketType.user)
@guild_only()
async def _stop(self, ctx: Context):
if not await database.get_guild(ctx.guild.id): return await ctx.respond(embed=ChristmasEmbed(title="❌ 에러!", description="서버가 가입되어있지 않아요! 서버를 가입해주세요!", color=Color.red()),ephemeral=True)
await ctx.defer(ephemeral=True)
get_guild = await database.get_guild(ctx.guild.id)
if not get_guild["music"] == True: return await ctx.respond(embed=Music_Embed.music_notenable(), ephemeral=True)
if ctx.author.voice == None or ctx.author.voice.channel == None: return await ctx.respond(embed=Music_Embed.author_not_voice(), ephemeral=True)
node = wavelink.Pool.get_node()
player = node.get_player(ctx.guild.id)
if player == None: return await ctx.respond(embed=Music_Embed.music_not_playing(), ephemeral=True)
await player.stop()
await ctx.me.voice.disconnect()
await ctx.respond(embed=Music_Embed.music_stop())
2023-12-02 06:03:50 +00:00
2023-11-26 04:27:34 +00:00
def setup(bot):
bot.add_cog(CMusic(bot))