Include minimal working example
This commit is contained in:
parent
cb782ce3d8
commit
d06bfce837
@ -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.
|
import discord
|
||||||
# The first page has the "left" button disabled, because there is no left page to go to...
|
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):
|
class FirstPageComps(View):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@ -82,7 +99,7 @@ class MiddlePageComps(View):
|
|||||||
self.stop()
|
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):
|
class LastPageComps(View):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@ -177,3 +194,17 @@ async def paginate(
|
|||||||
embed=embed,
|
embed=embed,
|
||||||
view=view,
|
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")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user