Move connect_channel into function

This commit is contained in:
Choco
2023-03-08 12:07:32 +08:00
parent cac4d63e82
commit b63301fa24
3 changed files with 20 additions and 36 deletions

View File

@@ -15,7 +15,8 @@ from function import (
playlist_name,
embed_color,
get_aliases,
cooldown_check
cooldown_check,
connect_channel
)
from datetime import datetime
@@ -68,23 +69,6 @@ async def search_playlist(url: str, requester: discord.Member, timeNeed=True):
return None
return tracks | ({'time': ctime(time)} if timeNeed else {})
async def connect_channel(ctx: commands.Context, channel: discord.VoiceChannel = None) -> voicelink.Player:
try:
channel = channel or ctx.author.voice.channel
except:
raise voicelink.VoicelinkException(
get_lang(ctx.guild.id, 'noChannel'))
check = channel.permissions_for(ctx.guild.me)
if check.connect == False or check.speak == False:
raise voicelink.VoicelinkException(
get_lang(ctx.guild.id, 'noPermission'))
player: voicelink.Player = await channel.connect(cls=voicelink.Player(ctx.bot, channel, ctx))
return player
class Playlists(commands.Cog, name="playlist"):
def __init__(self, bot: commands.Bot) -> None:
self.bot = bot