Copy the GlobalView implementation into a file such as /utils/views/base.py, then import and subclass it where needed.
Example:
/base.py (paste the implementation):
# (paste GlobalView implementation here)/something.py:
from base import GlobalView
class Something(GlobalView):
...
# sending
v = Something(123) # 123 = user id
await some_channel.send(view=v)- Built-in user-id check (optional)
- Accept components directly in the constructor (pass items to
GlobalView(...)). - Error handler
- Timeout handler
disable_items_on_timeoutoption (default: False) — when enabled, the view disables children on timeout.attach_messagemethod to attach adiscord.MessageorInteractionCallbackResponseso the view can edit it on timeout.disable_all_children()to disable nested children recursively.- Insert items at a specific index using
insert_item_atandinsert_item_intohelpers. - Absolute view timeout support (schedules stop + on_timeout at the specified time).
- Ability to get combined text content from all TextDisplays, like the "Copy Text" button in the client.
You can attach a message to the view so it can edit it on timeout. Use attach_message(...) or set the message attribute directly.
Accepts either a discord.Message or an discord.InteractionCallbackResponse (the latter must contain a Message in resource).
When disable_items_on_timeout is True, the view will disable children on timeout and will edit this message.
You can use insert_item_at(...) to insert into the view's top-level children, or insert_item_into(...) to insert into a nested target (ActionRow, Section, Container, MediaGallery).
-
insert_item_at(index: int, /, item: discord.ui.Item) -> Self- Inserts an item at the specified index in the view's top-level children.
view.insert_item_at(0, discord.ui.TextDisplay("hello world"))
-
insert_item_into(target, *, index: int | None = None) -> Self- Inserts
itemintotarget's children list. The optionalindexargument controls the insertion point. targetcan be adiscord.ui.View,discord.ui.Container,discord.ui.Section,discord.ui.ActionRow, ordiscord.ui.MediaGallery.
view.insert_item_into(section, discord.ui.TextDisplay("hello world"), index=0)
- Inserts
-
October 9, 2025 — Added features and reliability improvements
- Accept components directly in the constructor (pass items to
GlobalView(...)). - Added
assign_messageto attach adiscord.MessageorInteractionCallbackResponseso the view can edit the message on timeout. - Added
insert_item_atandinsert_item_intohelpers (with overloads) to insert items into Views, Containers, Sections, ActionRows, and MediaGallerys at specific indices. - Added
disable_items_on_timeoutoption. When enabled the view will disable all children on timeout and automatically edit the attached message to persist the disabled state. - Added a
contenthelper to get allTextDisplaycontent in the view. - Improved
on_timeoutanddisable_all_childrento walk nested children and safely disable items. - Improved
on_errorto notify the interaction user with an ephemeral message and then call the base handler.
- Accept components directly in the constructor (pass items to
-
August 25, 2025
- Switched out
ui.Viewforui.LayoutView - Made
author_idoptional - Renamed
disable_all_items()todisable_all_children()
- Switched out
-
October 3, 2022
- Initial release
thank you soheab