Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ These changes are available on the `master` branch, but have not yet been releas

### Changed

- Changed `BaseView.on_timeout` and `Paginator.on_timeout` behavior: views no longer
raise errors on timeout.
([#3019](https://github.com/Pycord-Development/pycord/pull/3019))

### Fixed

- Fixed breaking change in `ui.Select` Generic typing by adding default values to
Expand Down
16 changes: 10 additions & 6 deletions discord/ext/pages/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

from __future__ import annotations

import contextlib
from typing import List

import discord
Expand Down Expand Up @@ -597,11 +598,12 @@ async def on_timeout(self) -> None:
page = self.pages[self.current_page]
page = self.get_page_content(page)
files = page.update_files()
await self.message.edit(
view=self,
files=files or [],
attachments=[],
)
async with contextlib.suppress(discord.HTTPException):
await self.message.edit(
view=self,
files=files or [],
attachments=[],
)

async def disable(
self,
Expand Down Expand Up @@ -709,7 +711,9 @@ async def goto_page(

try:
if interaction:
await interaction.response.defer() # needed to force webhook message edit route for files kwarg support
await (
interaction.response.defer()
) # needed to force webhook message edit route for files kwarg support
await interaction.followup.edit_message(
message_id=self.message.id,
content=page.content,
Expand Down
21 changes: 14 additions & 7 deletions discord/ui/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from __future__ import annotations

import asyncio
import contextlib
import os
import sys
import time
Expand All @@ -42,6 +43,8 @@

from typing_extensions import Self

import discord

from ..components import ActionRow as ActionRowComponent
from ..components import Button as ButtonComponent
from ..components import Component
Expand All @@ -55,7 +58,6 @@
from ..components import TextDisplay as TextDisplayComponent
from ..components import Thumbnail as ThumbnailComponent
from ..components import _component_factory
from ..utils import find
from .core import ItemInterface
from .item import ItemCallbackType, ViewItem

Expand Down Expand Up @@ -96,7 +98,6 @@ def _walk_all_components_v2(components: list[Component]) -> Iterator[Component]:


def _component_to_item(component: Component) -> ViewItem[V]:

if isinstance(component, ButtonComponent):
from .button import Button

Expand Down Expand Up @@ -309,7 +310,8 @@ async def on_timeout(self) -> None:
message = self.message

if message:
m = await message.edit(view=self)
async with contextlib.suppress(discord.HTTPException):
m = await message.edit(view=self)
if m:
self._message = m

Expand Down Expand Up @@ -681,7 +683,7 @@ def add_item(self, item: ViewItem[V]) -> Self:

if item._underlying.is_v2():
raise ValueError(
f"cannot use V2 components in View. Use DesignerView instead."
"cannot use V2 components in View. Use DesignerView instead."
)
if isinstance(item._underlying, ActionRowComponent):
for i in item.children:
Expand Down Expand Up @@ -718,7 +720,9 @@ def clear_items(self) -> None:
def refresh(self, components: list[Component]):
# This is pretty hacky at the moment
old_state: dict[tuple[int, str], ViewItem[V]] = {
(item.type.value, item.custom_id): item for item in self.children if item.is_dispatchable() # type: ignore
(item.type.value, item.custom_id): item
for item in self.children
if item.is_dispatchable() # type: ignore
}
children: list[ViewItem[V]] = [
item for item in self.children if not item.is_dispatchable()
Expand Down Expand Up @@ -878,7 +882,7 @@ def add_item(self, item: ViewItem[V]) -> Self:

if isinstance(item._underlying, (SelectComponent, ButtonComponent)):
raise ValueError(
f"cannot add Select or Button to DesignerView directly. Use ActionRow instead."
"cannot add Select or Button to DesignerView directly. Use ActionRow instead."
)

super().add_item(item)
Expand Down Expand Up @@ -942,7 +946,10 @@ def add_view(self, view: BaseView, message_id: int | None = None):
view._start_listening_from_store(self)
for item in view.walk_children():
if item.is_storable():
self._views[(item.type.value, message_id, item.custom_id)] = (view, item) # type: ignore
self._views[(item.type.value, message_id, item.custom_id)] = (
view,
item,
) # type: ignore

if message_id is not None:
self._synced_message_views[message_id] = view
Expand Down