Skip to main content

A simple pagination library for Discord.py embeds.

Project description

ezpage

A simple and efficient Python library for creating pagination in Discord bots using discord.py. ezpage makes it easy to handle multi-page embeds with navigation buttons.

Features

  • Simple and clean API for pagination.
  • Uses discord.ui.View for interactive navigation.
  • Automatically enables/disables buttons based on the current page.
  • Works seamlessly with discord.ext.commands and discord.app_commands.
  • Customizable timeout and behavior.

Installation

Prerequisites

Make sure you have the following installed:

  • Python 3.8+
  • discord.py version 2.0 or later

Install via pip

pip install ezpage

Usage

Basic Example

Here's how you can use ezpage to create paginated embeds in your bot:

import discord
from discord.ext import commands
from ezpage import PaginationView

bot = commands.Bot(command_prefix="!")

@bot.command()
async def help(ctx):
    embeds = [
        discord.Embed(title="Help - Page 1", description="This is the first page."),
        discord.Embed(title="Help - Page 2", description="This is the second page."),
        discord.Embed(title="Help - Page 3", description="This is the third page.")
    ]
    view = PaginationView(embeds)
    await ctx.send(embed=embeds[0], view=view)

bot.run("YOUR_BOT_TOKEN")

Using with Slash Commands

If you are using discord.app_commands, you can use pagination like this:

import discord
from discord import app_commands
from discord.ext import commands
from ezpage import PaginationView

class Help(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @app_commands.command(name="help", description="Show the help menu with pagination.")
    async def help(self, interaction: discord.Interaction):
        embeds = [
            discord.Embed(title="Help - Page 1", description="This is the first page."),
            discord.Embed(title="Help - Page 2", description="This is the second page."),
            discord.Embed(title="Help - Page 3", description="This is the third page.")
        ]
        view = PaginationView(embeds)
        await interaction.response.send_message(embed=embeds[0], view=view, ephemeral=True)

async def setup(bot):
    await bot.add_cog(Help(bot))

Or Embeds With Multiple Fields

import discord
from discord.ext import commands
from pagination import PaginationView

class HelpCommand(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @commands.command(name="help")
    async def help_command(self, ctx):
        embeds = []

        # Splitting embeds into multiple pages
        embed1 = discord.Embed(title="Help - Page 1", description="General Commands", color=discord.Color.blue())
        embed1.add_field(name="`/balance`", value="Check your balance", inline=False)
        embed1.add_field(name="`/shop`", value="View the shop", inline=False)
        embeds.append(embed1)

        embed2 = discord.Embed(title="Help - Page 2", description="Economy Commands", color=discord.Color.green())
        embed2.add_field(name="`/work`", value="Earn money by working", inline=False)
        embed2.add_field(name="`/gamble`", value="Try your luck at gambling", inline=False)
        embeds.append(embed2)

        embed3 = discord.Embed(title="Help - Page 3", description="Business Commands", color=discord.Color.purple())
        embed3.add_field(name="`/startbusiness`", value="Start your own business", inline=False)
        embed3.add_field(name="`/apply`", value="Apply for a job", inline=False)
        embeds.append(embed3)

        view = PaginationView(embeds)
        await ctx.send(embed=embeds[0], view=view)

async def setup(bot):
    await bot.add_cog(HelpCommand(bot))

Customization

Change Timeout

By default, PaginationView times out after 60 seconds. You can change this by passing timeout as an argument:

view = PaginationView(embeds, timeout=120)  # 120 seconds timeout

Custom Buttons

You can override the button behavior by subclassing PaginationView:

class CustomPaginationView(PaginationView):
    @discord.ui.button(emoji="⏮️", style=discord.ButtonStyle.blurple)
    async def first_page(self, interaction: discord.Interaction, button: discord.ui.Button):
        self.current_page = 0
        await self.update_message(interaction)

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Feel free to submit issues or pull requests on GitHub.

Enjoy using ezpage to simplify your Discord bot pagination! 🚀

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ezpage-1.0.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ezpage-1.0.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file ezpage-1.0.0.tar.gz.

File metadata

  • Download URL: ezpage-1.0.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for ezpage-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ba710b5e04e4167a0c4d599262342c794bb79a632559d19458f25cacc31a3cd6
MD5 528098d2c778d90a974e802380441750
BLAKE2b-256 866479302dc91cc6b8114820954f4e7e8f2040617dc9f16abfab19ff15c45624

See more details on using hashes here.

File details

Details for the file ezpage-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: ezpage-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for ezpage-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e21ba26c2e8143c45571ae588bb92887c0a005c3afd661d1d839f933164b56a3
MD5 1f9f2c534fbec40a949f4d75962870d9
BLAKE2b-256 b5e4997440410d9b664c1db846b1cadfd2b265fcc73f6a7e106fc03c00295839

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page