Compare commits
1 Commits
ImAnAgent/
...
Gnome-py/K
Author | SHA1 | Date | |
---|---|---|---|
|
e649f356be |
12
README.rst
12
README.rst
@@ -17,6 +17,18 @@ The Future of enhanced-discord.py
|
|||||||
--------------------------
|
--------------------------
|
||||||
|
|
||||||
Enhanced discord.py is a fork of Rapptz's discord.py, that went unmaintained (`gist <https://gist.github.com/Rapptz/4a2f62751b9600a31a0d3c78100287f1>`_)
|
Enhanced discord.py is a fork of Rapptz's discord.py, that went unmaintained (`gist <https://gist.github.com/Rapptz/4a2f62751b9600a31a0d3c78100287f1>`_)
|
||||||
|
|
||||||
|
It is currently maintained by (in alphabetical order)
|
||||||
|
|
||||||
|
- Chillymosh#8175
|
||||||
|
- Daggy#9889
|
||||||
|
- dank Had0cK#6081
|
||||||
|
- Dutchy#6127
|
||||||
|
- Eyesofcreeper#0001
|
||||||
|
- Gnome!#6669
|
||||||
|
- IAmTomahawkx#1000
|
||||||
|
- Jadon#2494
|
||||||
|
|
||||||
An overview of added features is available on the `custom features page <https://enhanced-dpy.readthedocs.io/en/latest/index.html#custom-features>`_.
|
An overview of added features is available on the `custom features page <https://enhanced-dpy.readthedocs.io/en/latest/index.html#custom-features>`_.
|
||||||
|
|
||||||
Key Features
|
Key Features
|
||||||
|
@@ -28,7 +28,6 @@ from __future__ import annotations
|
|||||||
import asyncio
|
import asyncio
|
||||||
import collections
|
import collections
|
||||||
import collections.abc
|
import collections.abc
|
||||||
from functools import cached_property
|
|
||||||
|
|
||||||
import inspect
|
import inspect
|
||||||
import importlib.util
|
import importlib.util
|
||||||
@@ -73,9 +72,7 @@ from .cog import Cog
|
|||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
import importlib.machinery
|
import importlib.machinery
|
||||||
|
|
||||||
from discord.role import Role
|
|
||||||
from discord.message import Message
|
from discord.message import Message
|
||||||
from discord.abc import PartialMessageableChannel
|
|
||||||
from ._types import (
|
from ._types import (
|
||||||
Check,
|
Check,
|
||||||
CoroFunc,
|
CoroFunc,
|
||||||
@@ -97,16 +94,9 @@ CXT = TypeVar("CXT", bound="Context")
|
|||||||
|
|
||||||
class _FakeSlashMessage(discord.PartialMessage):
|
class _FakeSlashMessage(discord.PartialMessage):
|
||||||
activity = application = edited_at = reference = webhook_id = None
|
activity = application = edited_at = reference = webhook_id = None
|
||||||
attachments = components = reactions = stickers = []
|
attachments = components = reactions = stickers = mentions = []
|
||||||
tts = False
|
|
||||||
|
|
||||||
raw_mentions = discord.Message.raw_mentions
|
|
||||||
clean_content = discord.Message.clean_content
|
|
||||||
channel_mentions = discord.Message.channel_mentions
|
|
||||||
raw_role_mentions = discord.Message.raw_role_mentions
|
|
||||||
raw_channel_mentions = discord.Message.raw_channel_mentions
|
|
||||||
|
|
||||||
author: Union[discord.User, discord.Member]
|
author: Union[discord.User, discord.Member]
|
||||||
|
tts = False
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_interaction(
|
def from_interaction(
|
||||||
@@ -118,22 +108,6 @@ class _FakeSlashMessage(discord.PartialMessage):
|
|||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
@cached_property
|
|
||||||
def mentions(self) -> List[Union[discord.Member, discord.User]]:
|
|
||||||
client = self._state._get_client()
|
|
||||||
if self.guild:
|
|
||||||
ensure_user = lambda id: self.guild.get_member(id) or client.get_user(id) # type: ignore
|
|
||||||
else:
|
|
||||||
ensure_user = client.get_user
|
|
||||||
|
|
||||||
return discord.utils._unique(filter(None, map(ensure_user, self.raw_mentions)))
|
|
||||||
|
|
||||||
@cached_property
|
|
||||||
def role_mentions(self) -> List[Role]:
|
|
||||||
if self.guild is None:
|
|
||||||
return []
|
|
||||||
return discord.utils._unique(filter(None, map(self.guild.get_role, self.raw_role_mentions)))
|
|
||||||
|
|
||||||
|
|
||||||
def when_mentioned(bot: Union[Bot, AutoShardedBot], msg: Message) -> List[str]:
|
def when_mentioned(bot: Union[Bot, AutoShardedBot], msg: Message) -> List[str]:
|
||||||
"""A callable that implements a command prefix equivalent to being mentioned.
|
"""A callable that implements a command prefix equivalent to being mentioned.
|
||||||
@@ -1292,7 +1266,7 @@ class BotBase(GroupMixin):
|
|||||||
|
|
||||||
# Make our fake message so we can pass it to ext.commands
|
# Make our fake message so we can pass it to ext.commands
|
||||||
message: discord.Message = _FakeSlashMessage.from_interaction(interaction, channel) # type: ignore
|
message: discord.Message = _FakeSlashMessage.from_interaction(interaction, channel) # type: ignore
|
||||||
message.content = f"/{command_name}"
|
message.content = f"/{command_name} "
|
||||||
|
|
||||||
# Add arguments to fake message content, in the right order
|
# Add arguments to fake message content, in the right order
|
||||||
ignore_params: List[inspect.Parameter] = []
|
ignore_params: List[inspect.Parameter] = []
|
||||||
@@ -1307,7 +1281,7 @@ class BotBase(GroupMixin):
|
|||||||
else:
|
else:
|
||||||
prefix = param.annotation.__commands_flag_prefix__
|
prefix = param.annotation.__commands_flag_prefix__
|
||||||
delimiter = param.annotation.__commands_flag_delimiter__
|
delimiter = param.annotation.__commands_flag_delimiter__
|
||||||
message.content += f" {prefix}{name}{delimiter}{option['value']}" # type: ignore
|
message.content += f"{prefix}{name} {option['value']}{delimiter}" # type: ignore
|
||||||
continue
|
continue
|
||||||
|
|
||||||
option = next((o for o in command_options if o["name"] == name), None)
|
option = next((o for o in command_options if o["name"] == name), None)
|
||||||
@@ -1323,9 +1297,9 @@ class BotBase(GroupMixin):
|
|||||||
):
|
):
|
||||||
# String with space in without "consume rest"
|
# String with space in without "consume rest"
|
||||||
option = cast(_ApplicationCommandInteractionDataOptionString, option)
|
option = cast(_ApplicationCommandInteractionDataOptionString, option)
|
||||||
message.content += f" {_quote_string_safe(option['value'])}"
|
message.content += f"{_quote_string_safe(option['value'])} "
|
||||||
else:
|
else:
|
||||||
message.content += f' {option.get("value", "")}'
|
message.content += f'{option.get("value", "")} '
|
||||||
|
|
||||||
ctx = await self.get_context(message)
|
ctx = await self.get_context(message)
|
||||||
ctx._ignored_params = ignore_params
|
ctx._ignored_params = ignore_params
|
||||||
|
@@ -1694,9 +1694,7 @@ class Group(GroupMixin[CogT], Command[CogT, P, T]):
|
|||||||
"name": self.name,
|
"name": self.name,
|
||||||
"type": int(not (nested - 1)) + 1,
|
"type": int(not (nested - 1)) + 1,
|
||||||
"description": self.short_doc or "no description",
|
"description": self.short_doc or "no description",
|
||||||
"options": [
|
"options": [cmd.to_application_command(nested=nested + 1) for cmd in sorted(self.commands, key=lambda x: x.name)],
|
||||||
cmd.to_application_command(nested=nested + 1) for cmd in sorted(self.commands, key=lambda x: x.name)
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -455,7 +455,7 @@ class BadInviteArgument(BadArgument):
|
|||||||
This inherits from :exc:`BadArgument`
|
This inherits from :exc:`BadArgument`
|
||||||
|
|
||||||
.. versionadded:: 1.5
|
.. versionadded:: 1.5
|
||||||
|
|
||||||
Attributes
|
Attributes
|
||||||
-----------
|
-----------
|
||||||
argument: :class:`str`
|
argument: :class:`str`
|
||||||
|
@@ -153,38 +153,38 @@ class GatewayRatelimiter:
|
|||||||
await asyncio.sleep(delta)
|
await asyncio.sleep(delta)
|
||||||
|
|
||||||
|
|
||||||
class KeepAliveHandler(threading.Thread):
|
class KeepAliveHandler:
|
||||||
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
def __init__(self, *, ws: DiscordWebSocket, shard_id: int = None, interval: float = None) -> None:
|
||||||
ws = kwargs.pop("ws")
|
|
||||||
interval = kwargs.pop("interval", None)
|
|
||||||
shard_id = kwargs.pop("shard_id", None)
|
|
||||||
threading.Thread.__init__(self, *args, **kwargs)
|
|
||||||
self.ws: DiscordWebSocket = ws
|
self.ws: DiscordWebSocket = ws
|
||||||
self._main_thread_id: int = ws.thread_id
|
|
||||||
self.interval: Optional[float] = interval
|
|
||||||
self.daemon: bool = True
|
|
||||||
self.shard_id: Optional[int] = shard_id
|
self.shard_id: Optional[int] = shard_id
|
||||||
|
self.interval: Optional[float] = interval
|
||||||
|
self.heartbeat_timeout: float = self.ws._max_heartbeat_timeout
|
||||||
|
|
||||||
self.msg: str = "Keeping shard ID %s websocket alive with sequence %s."
|
self.msg: str = "Keeping shard ID %s websocket alive with sequence %s."
|
||||||
self.block_msg: str = "Shard ID %s heartbeat blocked for more than %s seconds."
|
self.block_msg: str = "Shard ID %s heartbeat blocked for more than %s seconds."
|
||||||
self.behind_msg: str = "Can't keep up, shard ID %s websocket is %.1fs behind."
|
self.behind_msg: str = "Can't keep up, shard ID %s websocket is %.1fs behind."
|
||||||
self._stop_ev: threading.Event = threading.Event()
|
self._stop_ev: asyncio.Event = asyncio.Event()
|
||||||
self._last_ack: float = time.perf_counter()
|
|
||||||
self._last_send: float = time.perf_counter()
|
self._last_send: float = time.perf_counter()
|
||||||
self._last_recv: float = time.perf_counter()
|
self._last_recv: float = time.perf_counter()
|
||||||
|
self._last_ack: float = time.perf_counter()
|
||||||
self.latency: float = float("inf")
|
self.latency: float = float("inf")
|
||||||
self.heartbeat_timeout: float = ws._max_heartbeat_timeout
|
|
||||||
|
|
||||||
def run(self) -> None:
|
async def run(self) -> None:
|
||||||
while not self._stop_ev.wait(self.interval):
|
while True:
|
||||||
|
try:
|
||||||
|
await asyncio.wait_for(self._stop_ev.wait(), timeout=self.interval)
|
||||||
|
except asyncio.TimeoutError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
|
||||||
if self._last_recv + self.heartbeat_timeout < time.perf_counter():
|
if self._last_recv + self.heartbeat_timeout < time.perf_counter():
|
||||||
_log.warning(
|
_log.warning(
|
||||||
"Shard ID %s has stopped responding to the gateway. Closing and restarting.", self.shard_id
|
"Shard ID %s has stopped responding to the gateway. Closing and restarting.", self.shard_id
|
||||||
)
|
)
|
||||||
coro = self.ws.close(4000)
|
|
||||||
f = asyncio.run_coroutine_threadsafe(coro, loop=self.ws.loop)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
f.result()
|
await self.ws.close(4000)
|
||||||
except Exception:
|
except Exception:
|
||||||
_log.exception("An error occurred while stopping the gateway. Ignoring.")
|
_log.exception("An error occurred while stopping the gateway. Ignoring.")
|
||||||
finally:
|
finally:
|
||||||
@@ -193,24 +193,18 @@ class KeepAliveHandler(threading.Thread):
|
|||||||
|
|
||||||
data = self.get_payload()
|
data = self.get_payload()
|
||||||
_log.debug(self.msg, self.shard_id, data["d"])
|
_log.debug(self.msg, self.shard_id, data["d"])
|
||||||
coro = self.ws.send_heartbeat(data)
|
|
||||||
f = asyncio.run_coroutine_threadsafe(coro, loop=self.ws.loop)
|
|
||||||
try:
|
try:
|
||||||
# block until sending is complete
|
# block until sending is complete
|
||||||
total = 0
|
total = 0
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
f.result(10)
|
await asyncio.wait_for(self.ws.send_heartbeat(data), timeout=10)
|
||||||
break
|
break
|
||||||
except concurrent.futures.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
total += 10
|
total += 10
|
||||||
try:
|
|
||||||
frame = sys._current_frames()[self._main_thread_id]
|
stack = "".join(traceback.format_stack())
|
||||||
except KeyError:
|
msg = f"{self.block_msg}\nLoop traceback (most recent call last):\n{stack}"
|
||||||
msg = self.block_msg
|
|
||||||
else:
|
|
||||||
stack = "".join(traceback.format_stack(frame))
|
|
||||||
msg = f"{self.block_msg}\nLoop thread traceback (most recent call last):\n{stack}"
|
|
||||||
_log.warning(msg, self.shard_id, total)
|
_log.warning(msg, self.shard_id, total)
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -225,6 +219,10 @@ class KeepAliveHandler(threading.Thread):
|
|||||||
"d": self.ws.sequence, # type: ignore
|
"d": self.ws.sequence, # type: ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def start(self) -> None:
|
||||||
|
self.ws.loop.create_task(self.run())
|
||||||
|
|
||||||
def stop(self) -> None:
|
def stop(self) -> None:
|
||||||
self._stop_ev.set()
|
self._stop_ev.set()
|
||||||
|
|
||||||
|
@@ -188,8 +188,8 @@ class HTTPClient:
|
|||||||
self.proxy_auth: Optional[aiohttp.BasicAuth] = proxy_auth
|
self.proxy_auth: Optional[aiohttp.BasicAuth] = proxy_auth
|
||||||
self.use_clock: bool = not unsync_clock
|
self.use_clock: bool = not unsync_clock
|
||||||
|
|
||||||
u_agent = "DiscordBot (https://github.com/iDevision/enhanced-discord.py {0}) Python/{1[0]}.{1[1]} aiohttp/{2}"
|
user_agent = "DiscordBot (https://github.com/Rapptz/discord.py {0}) Python/{1[0]}.{1[1]} aiohttp/{2}"
|
||||||
self.user_agent: str = u_agent.format(__version__, sys.version_info, aiohttp.__version__)
|
self.user_agent: str = user_agent.format(__version__, sys.version_info, aiohttp.__version__)
|
||||||
|
|
||||||
def recreate(self) -> None:
|
def recreate(self) -> None:
|
||||||
if self.__session.closed:
|
if self.__session.closed:
|
||||||
|
1274
docs/api.rst
1274
docs/api.rst
File diff suppressed because it is too large
Load Diff
@@ -49,7 +49,7 @@ autodoc_typehints = "none"
|
|||||||
# napoleon_attr_annotations = False
|
# napoleon_attr_annotations = False
|
||||||
|
|
||||||
extlinks = {
|
extlinks = {
|
||||||
"issue": ("https://github.com/iDevision/enhanced-discord.py/issues/%s", "GH-"),
|
"issue": ("https://github.com/Rapptz/discord.py/issues/%s", "GH-"),
|
||||||
}
|
}
|
||||||
|
|
||||||
# Links used for cross-referencing stuff in other documentation
|
# Links used for cross-referencing stuff in other documentation
|
||||||
@@ -168,8 +168,9 @@ html_context = {
|
|||||||
|
|
||||||
resource_links = {
|
resource_links = {
|
||||||
"discord": "https://discord.gg/TvqYBrGXEm",
|
"discord": "https://discord.gg/TvqYBrGXEm",
|
||||||
"issues": "https://github.com/iDevision/enhanced-discord.py/issues",
|
"issues": "https://github.com/Rapptz/discord.py/issues",
|
||||||
"examples": f"https://github.com/iDevision/enhanced-discord.py/tree/{branch}/examples",
|
"discussions": "https://github.com/Rapptz/discord.py/discussions",
|
||||||
|
"examples": f"https://github.com/Rapptz/discord.py/tree/{branch}/examples",
|
||||||
}
|
}
|
||||||
|
|
||||||
# Theme options are theme-specific and customize the look and feel of a theme
|
# Theme options are theme-specific and customize the look and feel of a theme
|
||||||
|
@@ -38,6 +38,7 @@ If you're having trouble with something, these resources might help.
|
|||||||
- Ask us and hang out with us in our :resource:`Discord <discord>` server.
|
- Ask us and hang out with us in our :resource:`Discord <discord>` server.
|
||||||
- If you're looking for something specific, try the :ref:`index <genindex>` or :ref:`searching <search>`.
|
- If you're looking for something specific, try the :ref:`index <genindex>` or :ref:`searching <search>`.
|
||||||
- Report bugs in the :resource:`issue tracker <issues>`.
|
- Report bugs in the :resource:`issue tracker <issues>`.
|
||||||
|
- Ask in our :resource:`GitHub discussions page <discussions>`.
|
||||||
|
|
||||||
Extensions
|
Extensions
|
||||||
------------
|
------------
|
||||||
|
@@ -1,210 +0,0 @@
|
|||||||
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,
|
|
||||||
author_id: int,
|
|
||||||
):
|
|
||||||
super().__init__()
|
|
||||||
self.value = None
|
|
||||||
self.author_id = author_id
|
|
||||||
|
|
||||||
async def interaction_check(
|
|
||||||
self,
|
|
||||||
interaction: Interaction,
|
|
||||||
):
|
|
||||||
return interaction.user.id == self.author_id
|
|
||||||
|
|
||||||
@discord.ui.button(
|
|
||||||
style=ButtonStyle.primary,
|
|
||||||
disabled=True,
|
|
||||||
label="Left",
|
|
||||||
)
|
|
||||||
async def left(
|
|
||||||
self,
|
|
||||||
button: discord.ui.Button,
|
|
||||||
interaction: Interaction,
|
|
||||||
):
|
|
||||||
self.value = "left"
|
|
||||||
self.stop()
|
|
||||||
|
|
||||||
@discord.ui.button(
|
|
||||||
style=ButtonStyle.primary,
|
|
||||||
label="Right",
|
|
||||||
)
|
|
||||||
async def right(
|
|
||||||
self,
|
|
||||||
button: discord.ui.Button,
|
|
||||||
interaction: Interaction,
|
|
||||||
):
|
|
||||||
self.value = "right"
|
|
||||||
self.stop()
|
|
||||||
|
|
||||||
|
|
||||||
# The middle pages have both left and right buttons available
|
|
||||||
class MiddlePageComps(View):
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
author_id: int,
|
|
||||||
):
|
|
||||||
super().__init__()
|
|
||||||
self.value = None
|
|
||||||
self.author_id = author_id
|
|
||||||
|
|
||||||
async def interaction_check(
|
|
||||||
self,
|
|
||||||
interaction: Interaction,
|
|
||||||
):
|
|
||||||
return interaction.user.id == self.author_id
|
|
||||||
|
|
||||||
@discord.ui.button(
|
|
||||||
style=ButtonStyle.primary,
|
|
||||||
label="Left",
|
|
||||||
)
|
|
||||||
async def left(
|
|
||||||
self,
|
|
||||||
button: discord.ui.Button,
|
|
||||||
interaction: Interaction,
|
|
||||||
):
|
|
||||||
self.value = "left"
|
|
||||||
self.stop()
|
|
||||||
|
|
||||||
@discord.ui.button(
|
|
||||||
style=ButtonStyle.primary,
|
|
||||||
label="Right",
|
|
||||||
)
|
|
||||||
async def right(
|
|
||||||
self,
|
|
||||||
button: discord.ui.Button,
|
|
||||||
interaction: Interaction,
|
|
||||||
):
|
|
||||||
self.value = "right"
|
|
||||||
self.stop()
|
|
||||||
|
|
||||||
|
|
||||||
# The last page has the right button disabled, because there's no right page to go to
|
|
||||||
class LastPageComps(View):
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
author_id: int,
|
|
||||||
):
|
|
||||||
super().__init__()
|
|
||||||
self.value = None
|
|
||||||
self.author_id = author_id
|
|
||||||
|
|
||||||
async def interaction_check(
|
|
||||||
self,
|
|
||||||
interaction: Interaction,
|
|
||||||
):
|
|
||||||
return interaction.user.id == self.author_id
|
|
||||||
|
|
||||||
@discord.ui.button(
|
|
||||||
style=ButtonStyle.primary,
|
|
||||||
label="Left",
|
|
||||||
)
|
|
||||||
async def left(
|
|
||||||
self,
|
|
||||||
button: discord.ui.Button,
|
|
||||||
interaction: Interaction,
|
|
||||||
):
|
|
||||||
self.value = "left"
|
|
||||||
self.stop()
|
|
||||||
|
|
||||||
@discord.ui.button(
|
|
||||||
style=ButtonStyle.primary,
|
|
||||||
label="Right",
|
|
||||||
disabled=True,
|
|
||||||
)
|
|
||||||
async def right(
|
|
||||||
self,
|
|
||||||
button: discord.ui.Button,
|
|
||||||
interaction: Interaction,
|
|
||||||
):
|
|
||||||
self.value = "right"
|
|
||||||
self.stop()
|
|
||||||
|
|
||||||
|
|
||||||
# Now we define the function that will take care of the pagination for us. It will take a list of Embeds and allow the user to cycle between them using left/right buttons
|
|
||||||
# There is also an optional title parameter in case you want to give your paginator a title, it will display in the embed title, for example if the title is Book
|
|
||||||
# then the title will look like "Book | Page 1/2". This is very optional and can be removed
|
|
||||||
async def paginate(
|
|
||||||
ctx,
|
|
||||||
pages: list,
|
|
||||||
title: str = None,
|
|
||||||
):
|
|
||||||
|
|
||||||
total_pages = len(pages)
|
|
||||||
first_page = pages[0]
|
|
||||||
last_page = pages[-1]
|
|
||||||
current_page = first_page
|
|
||||||
index = 0
|
|
||||||
|
|
||||||
embed = first_page
|
|
||||||
if title:
|
|
||||||
embed.title = f"{title} | Page {index+1}/{total_pages}"
|
|
||||||
|
|
||||||
view = FirstPageComps(ctx.author.id)
|
|
||||||
# Here we send the message with the view of the first page and the FirstPageComps buttons
|
|
||||||
msg = await ctx.send(
|
|
||||||
embed=embed,
|
|
||||||
view=view,
|
|
||||||
)
|
|
||||||
|
|
||||||
# The default timeout for Views is 3 minutes, but if a user selects to scroll between pages the timer will be reset.
|
|
||||||
# If the timer reaches 0, though, the loop will just silently stop.
|
|
||||||
while True:
|
|
||||||
wait = await view.wait()
|
|
||||||
if wait:
|
|
||||||
return
|
|
||||||
|
|
||||||
if view.value == "right":
|
|
||||||
index += 1
|
|
||||||
current_page = pages[index]
|
|
||||||
view = MiddlePageComps(ctx.author.id) if current_page != last_page else LastPageComps(ctx.author.id)
|
|
||||||
embed = current_page
|
|
||||||
if title:
|
|
||||||
embed.title = f"{title} | Page {index+1}/{total_pages}"
|
|
||||||
|
|
||||||
elif view.value == "left":
|
|
||||||
index -= 1
|
|
||||||
current_page = pages[index]
|
|
||||||
view = MiddlePageComps(ctx.author.id) if current_page != first_page else FirstPageComps(ctx.author.id)
|
|
||||||
embed = current_page
|
|
||||||
if title:
|
|
||||||
embed.title = f"{title} | Page {index+1}/{total_pages}"
|
|
||||||
|
|
||||||
await msg.edit(
|
|
||||||
embed=embed,
|
|
||||||
view=view,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
bot = Bot()
|
|
||||||
|
|
||||||
# To test our new function, let's create a list of a couple Embeds and let our paginator deal with the sending and buttons
|
|
||||||
@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