Giter VIP home page Giter VIP logo

button_paginator's Introduction

A python library created to make button pagination easy


To install you need git installed. After installing it, run

pip install git+https://github.com/cop-discord/button_paginator.git

Simple example:

import button_paginator as pg

@bot.command()
async def test(ctx):
	embeds = pg.embed_creator("Very long text"*10000, 1995, prefix='```\n', suffix='\n```')
	paginator = pg.Paginator(bot, embeds, ctx, invoker=ctx.author.id)
	paginator.default_pagination()
	await paginator.start()

Slightly more complicated example:

import button_paginator as pg

@bot.command()
async def test(ctx):
	embeds = pg.embed_creator("Very long text"*10000, 1995, prefix='```\n', suffix='\n```')
	paginator = pg.Paginator(bot, embeds, ctx, invoker=ctx.author.id)
	paginator.add_button('prev', emoji='◀')
	paginator.add_button('delete', label='Close the paginator', emoji='⏹')
	paginator.add_button('next', emoji='▶')
	await paginator.start()
  • All actions
  • "first": Goes to the first embed
  • "prev"/"previous"/"back": Goes to the embed before the current embed
  • "delete": Deletes the message
  • "next": Goes to the embed after the current embed
  • "last": Goes to the last embed
  • "end": Disables all the buttons
  • "page"/"show": Shows the current embed number (always disabled)
  • "goto": same as page/show will show the current embed number but when pressed will prompt the user to type a page number then will go to the number written
  • "lock": Removes all the buttons

Since pg.Paginator is a normal discord.ui.View subclassed class, you can add your own buttons to it!

import button_paginator as pg

class some_button(discord.ui.Button):
	def __init__(self):
		super().__init__(label='Hi', style=discord.ButtonStyle.danger)

@bot.command()
async def test(ctx):
	embeds = pg.embed_creator("Very long text"*10000, 1995, prefix='```\n', suffix='\n```')
	paginator = pg.Paginator(bot, embeds, ctx, invoker=ctx.author.id)
	paginator.default_pagination()
	paginator.add_item(some_button())
	await paginator.start()

This isn't only for embeds too!

import button_paginator as pg

@bot.command()
async def test(ctx):
	contents = ('Hello World!', discord.Embed(title='Hello World!'), ('Hello World!', discord.Embed(title="Hello World!")))
	# Does not support attachments
	paginator = pg.Paginator(bot, contents, ctx, invoker=ctx.author.id)
	paginator.default_pagination()
	await paginator.start()

Credits to andrewthederp for most of this library. I will be doing updates / providing help.

button_paginator's People

Contributors

cop-discord avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.