Guest User

Untitled

a guest
Nov 21st, 2023
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. class MusicPlatform(disnake.ui.Select):
  2. def __init__(self, bot: commands.bot) -> None:
  3. self.bot = bot
  4.  
  5. options = [
  6. disnake.SelectOption(label="Youtube", description="Youtube music"),
  7. disnake.SelectOption(label="Spotify", description="Spotify music")
  8. ]
  9. super().__init__(
  10. placeholder="Choose a music platform",
  11. min_values=1,
  12. max_values=1,
  13. options=options,
  14. custom_id="music_platform"
  15. )
  16.  
  17. class Music(commands.Cog):
  18. def __init__(self, bot: commands.Bot):
  19. super(Music, self).__init__()
  20. self.bot = bot
  21. self.pool = mafic.NodePool(self.bot)
  22. self.bot.loop.create_task(self.add_nodes())
  23.  
  24. async def add_nodes(self):
  25. await self.pool.create_node(
  26. label="MAIN",
  27. host="localhost",
  28. port=2333,
  29. password="youshallnotpass",
  30. )
  31.  
  32. @commands.command()
  33. async def play(self, ctx: commands.Context, *, query: str = None):
  34. ErrorEmbed = disnake.Embed(color=disnake.Color.red())
  35. """
  36. Play a song from spotify
  37. """
  38. if not query:
  39. ErrorEmbed.title = "Please provide a query/URL to search"
  40. return await ctx.send(embed=ErrorEmbed)
  41.  
  42. if not getattr(ctx.author.voice, "channel", None):
  43. ErrorEmbed.title = "Join a voice channel first"
  44. return await ctx.send(embed=ErrorEmbed)
  45.  
  46. voice = ctx.author.voice.channel
  47.  
  48. player: MusicPlayer = ctx.guild.voice_client or await voice.connect(
  49. cls=MusicPlayer # type: ignore
  50. )
  51.  
  52. select = MusicPlatform(self.bot)
  53. view = disnake.ui.View().add_item(select)
  54. await ctx.channel.send("Choose platform:", view=view)
  55. await self.bot.wait_for(
  56. "on_dropdown",
  57. check=lambda i: i.custom_id == "music_platform" and i.user == ctx.author,
  58. )
  59. print(select.values[0])
  60.  
  61. selected_platform = select.values[0]
  62.  
  63. if selected_platform == "Spotify":
  64. tracks = await player.fetch_tracks(query, search_type="spsearch")
  65. elif selected_platform == "Youtube":
  66. tracks = await player.fetch_tracks(query)
  67. else:
  68. return await ctx.send("Invalid platform selected")
  69. ...
Advertisement
Add Comment
Please, Sign In to add comment