not-lain commited on
Commit
ac89633
·
1 Parent(s): 6ea2227

add queue command

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py CHANGED
@@ -36,6 +36,7 @@ class MusicBot:
36
  'no_warnings': True,
37
  'extract_flat': 'in_playlist'
38
  }
 
39
 
40
  async def join_voice(self, ctx):
41
  if ctx.author.voice:
@@ -57,6 +58,7 @@ class MusicBot:
57
  info = ydl.extract_info(url, download=False)
58
  audio_url = info['url']
59
  title = info.get('title', 'Unknown title')
 
60
 
61
  # Create FFmpeg audio source
62
  ffmpeg_options = {
@@ -67,6 +69,7 @@ class MusicBot:
67
 
68
  def after_playing(error):
69
  self.is_playing = False
 
70
  if error:
71
  print(f"Playback error: {error}")
72
  asyncio.run_coroutine_threadsafe(self.play_next(ctx), bot.loop)
@@ -138,6 +141,31 @@ async def leave(interaction: discord.Interaction):
138
  else:
139
  await interaction.response.send_message('Bot is not in a voice channel!')
140
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  def run_discord_bot():
142
  bot.run(os.getenv('DISCORD_TOKEN'))
143
 
 
36
  'no_warnings': True,
37
  'extract_flat': 'in_playlist'
38
  }
39
+ self.currently_playing = None
40
 
41
  async def join_voice(self, ctx):
42
  if ctx.author.voice:
 
58
  info = ydl.extract_info(url, download=False)
59
  audio_url = info['url']
60
  title = info.get('title', 'Unknown title')
61
+ self.currently_playing = title
62
 
63
  # Create FFmpeg audio source
64
  ffmpeg_options = {
 
69
 
70
  def after_playing(error):
71
  self.is_playing = False
72
+ self.currently_playing = None
73
  if error:
74
  print(f"Playback error: {error}")
75
  asyncio.run_coroutine_threadsafe(self.play_next(ctx), bot.loop)
 
141
  else:
142
  await interaction.response.send_message('Bot is not in a voice channel!')
143
 
144
+ @bot.tree.command(name="queue", description="Show the current music queue")
145
+ async def queue(interaction: discord.Interaction):
146
+ await interaction.response.defer()
147
+
148
+ if not music_bot.is_playing and not music_bot.queue:
149
+ await interaction.followup.send("No songs in the queue!")
150
+ return
151
+
152
+ queue_list = []
153
+ if music_bot.currently_playing:
154
+ queue_list.append(f"Currently playing: {music_bot.currently_playing}")
155
+
156
+ if music_bot.queue:
157
+ with yt_dlp.YoutubeDL(music_bot.ydl_opts) as ydl:
158
+ for i, url in enumerate(music_bot.queue, 1):
159
+ try:
160
+ info = ydl.extract_info(url, download=False)
161
+ title = info.get('title', 'Unknown title')
162
+ queue_list.append(f"{i}. {title}")
163
+ except:
164
+ queue_list.append(f"{i}. {url}")
165
+
166
+ queue_text = "\n".join(queue_list)
167
+ await interaction.followup.send(f"**Music Queue:**\n{queue_text}")
168
+
169
  def run_discord_bot():
170
  bot.run(os.getenv('DISCORD_TOKEN'))
171