Repository navigation
Apologies for the wait, and for the size of this one. 4.0.0 is a very large release: about two months of work, much of it driven by the bots built on CascadeUI, folded into one update instead of a string of patches. A release of this size and scope is all but certain to need a 4.0.1, so expect a patch within the next few days, and please open an issue for anything that looks wrong.
The headline is the path from a click to the screen. A double-click no longer runs a button twice, a click on a control a rebuild removed no longer runs it, and a view's renders land in the order they were made. The Continue button on an ephemeral panel now resumes that panel in place, a value or callable of the wrong shape is refused where it is declared rather than on a later click, and the documentation is rewritten and reorganized, with a Guide that has diagrams and animations of each part.
This is a major release, and a breaking one. Most of its 69 breaking changes refuse input that 3.14.2 accepted. A few of them reach most bots. A button drops a person's second click while their first is still running, unless it sets allow_double_click=True. A select pick its callback leaves unanswered is answered with the view's current render, so a callback that only stores a pick now draws it. on_error() runs before the click is acknowledged, so an override that replied only through followup.send() answers first or uses respond(). Two changes alter a result without raising: regex() matches the whole value, and RetryConfig(max_retries=N) retries N times. Read Breaking and Upgrading from 3.x before you upgrade a bot.
What you'll reach for first: get_files() for views that draw their own images, dispatch_scoped() with a function for counts that two people click at once, and fields_in_modal for a form answered in one dialog.
Security
- A click on a control the view just removed no longer runs without its checks. Such a click ran the control's callback with no view, skipping the view's checks and the control's own
owner_only, so a public panel's owner-only button ran for anyone who clicked it before the edit landed. The click is now dropped, or taken by the control with the samecustom_idnow in its place.
Breaking
- A user's second click on a button is dropped while their first click on it is still running and has had no reply, edit, or modal. An Update button clicked twice on a one-at-a-time review screen updated an item nobody had seen. Another user's click still runs, and
allow_double_click=Trueon a button keeps the old behavior. on_error()runs before the click is acknowledged, as discord.py runs it. An override that answered throughinteraction.responseused to raiseInteractionResponded, so the person saw no error message. An override that replied only throughfollowup.send()relied on the earlier acknowledgement: reply throughrespond().regex()matches the whole value.regex(r"\d+")passed"12abc". A pattern written to check how a value begins now refuses every value that goes on: end it with.*.RetryConfig(max_retries=N)retries N times, sowith_retrymakes up to N + 1 calls. To keep the old count, lowermax_retriesby one.- A persistent view refuses a timeout. A number given as its
timeoutwas silently replaced withNone, and one assigned later froze the panel for everyone until a restart. It now raisesValueError.Noneand0are accepted. - A screen pushed from a panel with no owner has no owner either. It took whoever clicked as its owner and, with the default
owner_only, refused everyone else on a public message. A screen about the person who clicked names them:push(MyStats, interaction, user_id=interaction.user.id). - A scoped-state id must be a Discord id. A name,
True, or42.0built a key no other call reached, and now raisesTypeError. A string of digits stands for its number, so"042"and42read one slice. - A middleware that stops one of the library's own records raises
RuntimeError. A rate limiter that dropped every second action dropped view and registry records too, with nothing said: closed views kept their instance slots and panels were not restored after a restart. Once Discord has answered a send, and in a close, it is logged at ERROR instead. - Input of the wrong shape is refused where it is declared. A callable that cannot take what it will be given, a value of the wrong type, a key a letter or two off one the library reads, and a select or button Discord would reject now raise when they are passed, built, or defined, instead of failing on a later click. Upgrading from 3.x sorts them by how you meet them, and the CHANGELOG has every one.
Added
- A stability policy for 4.x defines which names are public, what minor and patch releases may change, and how a public name is deprecated before it is removed.
get_files()supplies the files a view'sattachment://references name. The library calls it on every send and on every edit that ships the view, and an edit uploads only when a file is new to the message or its contents changed.dispatch_scoped()takes a function of the slice's current value, so two panels clicked at once count both clicks.- Every view has a
botproperty, and a persistent view's is set beforeon_bind()runs. - The pattern hooks are public:
build_extra_items(),build_tab_rows(),build_progress_header(),freeze_components(), and the rest. fields_in_modalonFormViewandFormLayoutViewanswers every field in one Edit modal, with radio groups, checkbox groups, and Yes/No choices.- A wizard has
answers, carried with the current step acrosspop(), and a menu'son_category_selected()can keep the menu on screen by returningFalse. button_rowandtab_navtakeRowButtonentries, and achoice_rowChoicetakes akey, so a persistent panel's buttons keep their ids when a row changes.cascadeui.testinggrowsStubMessage,flush_notifications(),build_as_restored(), and a stub that answers a hybrid command'sContext.- The documentation is rewritten and reorganized, with Learn pages, a Guide with diagrams and animations of each part, How-to recipes, the Reference, and a Contribute section. A new example,
v2_player.py, is a music player card its own timer redraws.
Changed
- The Continue button brings the panel back in place: the same view on the same message, keeping its navigation, session, participants, and attributes. It appears 13.5 minutes after the panel was last used, not after its send.
- A
StatefulLayoutViewthat nothing has drawn yet is drawn from itsbuild_ui(), where the send refused it. FormLayoutViewdraws the form as one card, andWizardLayoutVieweach step.- An
instance_limitunder the defaultinstance_scope = "user_guild"applies in DMs. - A deleted message no longer costs a check of every live view, so a message delete costs the same at any number of views.
dispatch()raises its exceptions without logging them first.
Deprecated
- The roles pattern (
RolesLayoutView,PersistentRolesLayoutView,RoleCategory) keeps working through 4.x and is removed in 5.0.0. The persistence example shows a role panel built from aPersistentLayoutViewand aDynamicPersistentButton. - The pattern hooks' old private names keep working, with a
DeprecationWarning, until 5.0.0.
Removed
build_reopen_view(). The Continue resumes the same view, so a class that still defines it raisesTypeErrorwhen it is defined. Its work moves intoon_load()._build_refresh_button()and_safe_defer(), deprecated in 3.14.- Methods only the library calls are private, and a class that still defines one raises
TypeErrorwhen it is defined.
Fixed
- A click's render and the view's other renders land in the order they were made. A control the view disabled stays disabled when Discord reports an older edit late, and a message left on an older render is redrawn on the next click.
- A view closed right after a dispatch shows the change before it closes.
- A
build_ui(),on_load(), or pattern rebuild that raises part way leaves the panel as it was, instead of a panel cut short at the failing item. - An ephemeral panel used past its first fifteen minutes can still be closed and edited.
- One person's modal submission no longer runs another person's modal, and a dismissed modal no longer freezes the view that opened it.
- Components Discord would reject are refused before they reach it, naming the component: a select whose options repeat a value, a button with neither a label nor an emoji, an emoji Discord refuses, and a select whose bounds or defaults it refuses.
- A view or bot class that defines
__eq__sends, attaches, and closes normally. - A registry prune deletes only the row it checked, so a panel posted again under the key keeps working after a restart.
- A bot split into several processes stays in step. Each process restores only the panels on its own shards, and on PostgreSQL a saved slot another process changes is read back instead of written over.
- A PostgreSQL role holding only
SELECT,INSERT,UPDATE, andDELETEon the tables can run the bot once the owner has made them.
Documentation
Install
pip install pycascadeui==4.0.0
See the full CHANGELOG for every change in this release.
Full Changelog: v3.14.2...v4.0.0