Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MusicPlatform(disnake.ui.Select):
- def __init__(self, bot: commands.bot) -> None:
- self.bot = bot
- options = [
- disnake.SelectOption(label="Youtube", description="Youtube music"),
- disnake.SelectOption(label="Spotify", description="Spotify music")
- ]
- super().__init__(
- placeholder="Choose a music platform",
- min_values=1,
- max_values=1,
- options=options,
- custom_id="music_platform"
- )
- class Music(commands.Cog):
- def __init__(self, bot: commands.Bot):
- super(Music, self).__init__()
- self.bot = bot
- self.pool = mafic.NodePool(self.bot)
- self.bot.loop.create_task(self.add_nodes())
- async def add_nodes(self):
- await self.pool.create_node(
- label="MAIN",
- host="localhost",
- port=2333,
- password="youshallnotpass",
- )
- @commands.command()
- async def play(self, ctx: commands.Context, *, query: str = None):
- ErrorEmbed = disnake.Embed(color=disnake.Color.red())
- """
- Play a song from spotify
- """
- if not query:
- ErrorEmbed.title = "Please provide a query/URL to search"
- return await ctx.send(embed=ErrorEmbed)
- if not getattr(ctx.author.voice, "channel", None):
- ErrorEmbed.title = "Join a voice channel first"
- return await ctx.send(embed=ErrorEmbed)
- voice = ctx.author.voice.channel
- player: MusicPlayer = ctx.guild.voice_client or await voice.connect(
- cls=MusicPlayer # type: ignore
- )
- select = MusicPlatform(self.bot)
- view = disnake.ui.View().add_item(select)
- await ctx.channel.send("Choose platform:", view=view)
- await self.bot.wait_for(
- "on_dropdown",
- check=lambda i: i.custom_id == "music_platform" and i.user == ctx.author,
- )
- print(select.values[0])
- selected_platform = select.values[0]
- if selected_platform == "Spotify":
- tracks = await player.fetch_tracks(query, search_type="spsearch")
- elif selected_platform == "Youtube":
- tracks = await player.fetch_tracks(query)
- else:
- return await ctx.send("Invalid platform selected")
- ...
Advertisement
Add Comment
Please, Sign In to add comment