how to make a queue command for lavalink discord py

Solutions on MaxInterview for how to make a queue command for lavalink discord py by the best coders in the world

showing results for - "how to make a queue command for lavalink discord py"
Johanna
02 Aug 2018
1##This was in a cog
2from discord.ext import commands
3import lavalink
4from discord import utils
5from discord import Embed
6import re
7import math
8import discord
9
10url_rx = re.compile(r'https?://(?:www\.)?.+')
11
12class MusicCog(commands.Cog):
13  def __init__(self, bot):
14    self.bot = bot
15    self.bot.music = lavalink.Client(self.bot.user.id)
16    self.bot.music.add_node('localhost', 6666, 'Humpday!', 'na', 'music-node')
17    self.bot.add_listener(self.bot.music.voice_update_handler, 'on_socket_response')
18    self.bot.music.add_event_hook(self.track_hook)
19
20    async def cog_before_invoke(self, ctx):
21        guild_check = ctx.guild is not None
22 
23##below is ths maine queue command
24 @commands.command(name='queue')
25  async def queue(self, ctx, page: int = 1):
26    player = self.bot.music.player_manager.get(ctx.guild.id)
27
28    items_per_page = 10
29    pages = math.ceil(len(player.queue) / items_per_page)
30
31    start = (page - 1) * items_per_page
32    end = start + items_per_page
33
34    queue_list = ''
35    for index, track in enumerate(player.queue[start:end], start=start):
36      queue_list += f'`{index + 1}.` [**{track.title}**]({track.uri})\n'
37
38    embed = discord.Embed(colour=discord.Color.blurple(),
39                          description=f'**{len(player.queue)} tracks**\n\n{queue_list}')
40    embed.set_footer(text=f'Viewing page {page}/{pages}')
41    await ctx.send(embed=embed)
42
43##below this just finishes up the cog
44def setup(bot):
45  bot.add_cog(MusicCog(bot))
46##feel free to uses this