Include minimal working example
This commit is contained in:
		| @@ -1,5 +1,22 @@ | ||||
| # First we define 3 View subclasses that we will switch between depending on if we are viewing the first page, a page in the middle, or the last page. | ||||
| # The first page has the "left" button disabled, because there is no left page to go to... | ||||
| import discord | ||||
| from discord.ext import commands | ||||
| from discord import ButtonStyle, Embed, Interaction | ||||
| from discord.ui import Button, View | ||||
|  | ||||
|  | ||||
| class Bot(commands.Bot): | ||||
|     def __init__(self): | ||||
|         super().__init__( | ||||
|             command_prefix=commands.when_mentioned_or("$"), intents=discord.Intents(guilds=True, messages=True) | ||||
|         ) | ||||
|  | ||||
|     async def on_ready(self): | ||||
|         print(f"Logged in as {self.user} (ID: {self.user.id})") | ||||
|         print("------") | ||||
|  | ||||
|  | ||||
| # Define 3 View subclasses that we will switch between depending on if we are viewing the first page, a page in the middle, or the last page. | ||||
| # The first page has the "left" button disabled, because there is no left page to go to | ||||
| class FirstPageComps(View): | ||||
|     def __init__( | ||||
|         self, | ||||
| @@ -82,7 +99,7 @@ class MiddlePageComps(View): | ||||
|         self.stop() | ||||
|  | ||||
|  | ||||
| # The last page has the right button disabled, because there's no right page to go to anymore... | ||||
| # The last page has the right button disabled, because there's no right page to go to | ||||
| class LastPageComps(View): | ||||
|     def __init__( | ||||
|         self, | ||||
| @@ -177,3 +194,17 @@ async def paginate( | ||||
|             embed=embed, | ||||
|             view=view, | ||||
|         ) | ||||
|  | ||||
|  | ||||
| bot = Bot() | ||||
|  | ||||
| # To test our new function, let's create a list of a couple Embeds and send | ||||
| @bot.command() | ||||
| async def sendpages(ctx): | ||||
|     page1 = Embed(description="This is page 1") | ||||
|     page2 = Embed(description="This is page 2") | ||||
|     page3 = Embed(description="This is page 3") | ||||
|     await paginate(ctx, [page1, page2, page3]) | ||||
|  | ||||
|  | ||||
| bot.run("token") | ||||
|   | ||||
		Reference in New Issue
	
	Block a user