Search code examples
pythondiscorddiscord.py

Discordpy banlist with pagination


I was trying to do a banlist with pagination, I already have the part that send the banlist but I'm having trouble finding how to paginate something in Discordpy, here is the code if it's needed:

#COMMAND banlist
@cog_ext.cog_slash(name='banlist', description='List all baned users')
@commands.has_role(Staff_role)
async def banlogs(self,ctx):
    guild = ctx.guild
    bans = await guild.bans()
    embed = discord.Embed(title="Ban Logs", colour=discord.Color.red())
    for ban in bans:
        embed.add_field(name=f"Name: ", value=f"{ban.user}")
        embed.add_field(name="Is_bot?", value=f"{ban.user.bot}")
        embed.add_field(name="Reason: ", value=f"{ban.reason}")
    await ctx.send(embed=embed)

Is it possible to make that if the message has more that 10 users, create another page?


Solution

  • Rapptz, The owner of discord.py has created a module for helping with pagination, named discord-ext-menus.

    To install:

    $ python -m pip install -U git+https://github.com/rapptz/discord-ext-menus
    

    Useful things

    Source