58 lines
3.1 KiB
Python
58 lines
3.1 KiB
Python
from discord.utils import basic_autocomplete
|
|
from discord import Member, SlashCommandGroup, Option, AutocompleteContext, Color
|
|
from discord.ext.commands import Cog, cooldown, BucketType, command, has_permissions, bot_has_permissions, Context, guild_only, bot_has_guild_permissions, check
|
|
import wavelink
|
|
import random
|
|
from Christmas.Database import database
|
|
from Christmas.UI.Embed import Music_Embed, ChristmasEmbed
|
|
from Christmas.config import ChristmasConfig
|
|
|
|
class CMusic(Cog):
|
|
def __init__(self, bot):
|
|
self.bot = bot
|
|
self.config = ChristmasConfig()
|
|
|
|
MUSIC = SlashCommandGroup(name="음악", description="음악을 재생합니다.")
|
|
#
|
|
@MUSIC.command(name="재생", description="LOFI 음악을 재생합니다.")
|
|
@cooldown(1, 10, BucketType.user)
|
|
@guild_only()
|
|
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)
|
|
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
|
|
node = wavelink.Pool.get_node()
|
|
if node.get_player(ctx.guild.id) == None:
|
|
player = await ctx.author.voice.channel.connect(cls=wavelink.Player)
|
|
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())
|
|
|
|
|
|
def setup(bot):
|
|
bot.add_cog(CMusic(bot)) |