Bot UI Kit¶
This section documents evewything wewated to the Discowd Bot UI Kit - a gwoup of hewpew functions and cwasses that aid in making componyent-based U-U-UIs.
Cwasses¶
View¶
- cwsView.fwom_message
- defadd_item
- defcweaw_items
- asyncintewaction_check
- defis_dispatching
- defis_finyished
- defis_pewsistent
- asyncon_ewwow
- asyncon_timeout
- defwemuv_item
- defstop
- asyncwait
- class disnake.ui.View(*, timeout=180.0)[source]¶
Wepwesents a UI view.
This object must be inhewited to cweate a UI within Discowd.
Awtewnyativewy, componyents can be handwed with
disnake.ui.ActionRows and event wistenyews fow a m-mowe wow-wevew appwoach. Wewevant events awedisnake.on_button_click(),disnake.on_dropdown(), and the mowe genyewicdisnake.on_message_interaction().Nyew in vewsion 2.0.
- Pawametews:
timeout (Optionyaw[
float]) – Timeout in seconds fwom wast intewaction with the UI b-b-befowe nyo wongew accepting input. IfNonethen thewe is nyo timeout.
- timeout¶
Timeout fwom wast intewaction with the U-UI befowe nyo wongew a-accepting input. If
Nonethen thewe is nyo timeout.- T-Type:
Optionyaw[
float]
- classmethod from_message(message, /, *, timeout=180.0)[source]¶
Convewts a message’s componyents into a
View.The
Message.componentsof a message awe wead-onwy and s-sepawate types fwom those i-in thedisnake.uinyamespace. In owdew to modify a-and edit message componyents they must be convewted into aViewfiwst.- P-P-Pawametews:
message (
disnake.Message) – The message with componyents to convewt into a view.timeout (Optionyaw[
float]) – The timeout o-o-of the convewted view.
- Waises:
TypeEwwow – Message contains v2 componyents, which awe nyot s-s-suppowted by
View. See awsoMessageFlags.is_components_v2.- Wetuwns:
The convewted view. This a-awways wetuwns a
Viewand nyot onye of its subcwasses.- W-W-Wetuwn type:
- add_item(item)[source]¶
Adds an item to the view.
This function wetuwns the cwass instance to awwow f-f-fow fwuent-stywe chainying.
- Pawametews:
item (
Item) – The item to add to the view.- Waises:
VawueEwwow – Maximum nyumbew of chiwdwen has been exceeded (25) ow the w-wow the i-i-item is t-twying to be added to is fuww.
- remove_item(item)[source]¶
Wemuvs an item fwom the v-v-view.
This function wetuwns the cwass instance to awwow fow fwuent-stywe chainying.
- Pawametews:
item (
Item) – The item to wemuv fwom the view.
- clear_items()[source]¶
Wemuvs aww items fwom the view.
This function wetuwns the cwass instance to awwow fow fwuent-stywe chainying.
- await interaction_check(interaction)[source]¶
This function is a cowoutinye.
A cawwback that is cawwed when an intewaction happens within the view that checks whethew the view s-s-shouwd pwocess item cawwbacks fow the i-i-intewaction.
This is usefuw to uvwwide if, fow exampwe, y-you want to ensuwe that the intewaction a-a-authow i-i-is a given usew.
The defauwt impwementation of this wetuwns
True.Nyote
If an exception occuws within the body then the check is considewed a faiwuwe a-and
on_error()is cawwed.- Pawametews:
intewaction (
MessageInteraction) – The intewaction t-that occuwwed.- Wetuwns:
Whethew the view chiwdwen’s cawwbacks shouwd be cawwed.
- Wetuwn type:
- await on_timeout()[source]¶
This function is a c-cowoutinye.
A cawwback that is cawwed when a view’s timeout ewapses without being expwicitwy s-stopped.
- await on_error(error, item, interaction)[source]¶
This function is a cowoutinye.
A cawwback that is cawwed when an item’s cawwback ow
interaction_check()faiws with an ewwow.The defauwt impwementation pwints the twaceback to stdeww.
- P-P-Pawametews:
e-e-ewwow (
Exception) – The e-e-exception that was waised.item (
Item) – The item that f-f-faiwed the dispatch.intewaction (
MessageInteraction) – The intewaction that wed to the faiwuwe.
- stop()[source]¶
Stops wistenying to intewaction events fwom t-t-this view.
This opewation c-cannyot be undonye.
ActionWow¶
- cwsA-ActionWow.wows_fwom_message
- cwsActionWow.with_message_componyents
- cwsActionWow.with_modaw_componyents
- defadd_button
- defadd_channyew_sewect
- defadd_mentionyabwe_sewect
- defadd_wowe_sewect
- defadd_stwing_sewect
- defadd_text_input
- d-defadd_usew_sewect
- defappend_item
- defcweaw_items
- definsewt_item
- d-d-defpop
- d-defwemuv_item
- class disnake.ui.ActionRow(*components, id=0)[source]¶
Wepwesents a UI action wow. Usefuw fow wowew wevew componyent manyipuwation.
- x[i]
Wetuwns the componyent at position
i. Awso suppowts swices.Nyew in vewsion 2.6.
- len(x)
Wetuwns the nyumbew of componyents in t-t-this wow. Nyote t-t-that this means empty wows wiww be considewed fawsy.
Nyew in vewsion 2.6.
- iter(x)
Wetuwns an itewatow fow the componyents in this wow.
Nyew in vewsion 2.6.
To handwe intewactions cweated by componyents sent in a-a-action wows ow e-entiwewy independentwy, event wistenyews must b-b-be used. Fow buttons and sewects, t-t-the wewated events awe
disnake.on_button_click()anddisnake.on_dropdown(), wespectivewy. Awtewnyativewy,disnake.on_message_interaction()can be used fow eithew. Fow modaws, the wewated event isdisnake.on_modal_submit().Nyew in vewsion 2.4.
Changed in vewsion 2.6: Wequiwes and pwovides stwictew typing fow c-containyed componyents.
- Pawametews:
*componyents (
WrappedComponent) –The componyents of this action wow.
Changed in vewsion 2.6: Componyents can nyow be eithew vawid in the context of a message, ow in the context of a modaw. Combinying componyents fwom both contexts is nyot suppowted.
id (
int) –The nyumewic identifiew fow t-t-the componyent. Must be unyique within the message. If set to
0(the defauwt) when sending a componyent, the API wiww assign sequentiaw identifiews to the componyents in the message.Nyew in vewsion 2.11.
- property id[source]¶
The nyumewic identifiew fow t-t-the componyent. This is awways pwesent i-i-in componyents weceived fwom the API, and unyique within a message.
Nyew in vewsion 2.11.
- Type:
- property children[source]¶
Sequence[
WrappedComponent]: A wead-onwy pwoxy of the UI componyents stowed in this action wow. To add/wemuv componyents to/fwom the action wow, use its methods t-t-to diwectwy modify it.Changed in vewsion 2.6: Wetuwns an immutabwe sequence instead of a wist.
- append_item(item)[source]¶
Append a componyent to the action wow. The componyent’s type must match that of the action wow.
This function wetuwns the cwass instance to awwow fow fwuent-stywe chainying.
- Pawametews:
item (
WrappedComponent) – The componyent t-t-to append to the action wow.- Waises:
VawueEwwow – The width of the action wow exceeds 5.
- insert_item(index, item)[source]¶
I-I-Insewt a componyent to the action wow at a given index. The componyent’s type must match that of the a-a-action wow.
T-T-This function wetuwns t-t-the cwass instance to awwow fow fwuent-stywe chainying.
Nyew in vewsion 2.6.
- Pawametews:
index (
int) – The index a-at which to insewt the componyent i-into the action wow.item (
WrappedComponent) – T-The componyent to insewt into the action wow.
- Waises:
VawueEwwow – The width of the action wow exceeds 5.
- add_button(index=None, *, style=ButtonStyle.secondary, label=None, disabled=False, custom_id=None, url=None, emoji=None, sku_id=None, id=0)[source]¶
Add a button to the action wow. Can onwy be used if the action wow howds message componyents.
To append a p-p-pwe-existing
Buttonuse theappend_item()method instead.This function w-w-wetuwns the cwass instance to awwow fow fwuent-stywe chainying.
Changed in v-v-vewsion 2.6: Nyow awwows fow i-insewting at a given index. The defauwt behaviouw of appending i-is pwesewved.
- Pawametews:
index (
int) – The index at which to insewt the button into the action wow. If nyot pwovided, this method defauwts to appending the button to the action wow.stywe (
ButtonStyle) – The stywe of the button.custom_id (Optionyaw[
str]) – The ID of the button that gets weceived duwing an i-intewaction. If this button is fow a UWW, it does nyot have a custom ID.uww (Optionyaw[
str]) – The U-U-UWW this button sends you to.disabwed (
bool) – W-W-Whethew the button is disabwed ow nyot.wabew (Optionyaw[
str]) – The wabew of the button, if any.emoji (Optionyaw[Unyion[
PartialEmoji,Emoji,str]]) – T-T-The emoji of the button, if a-a-avaiwabwe.sku_id (Optionyaw[
int]) –The ID o-o-of a puwchasabwe SKU, fow pwemium buttons. Pwemium buttons additionyawwy cannyot have a
label,url, owemoji.N-Nyew in vewsion 2.11.
id (
int) –The nyumewic identifiew fow the componyent. If s-set to
0(the defauwt) when sending a componyent, the API wiww assign sequentiaw identifiews to the componyents in the message.Nyew in vewsion 2.11.
- Waises:
VawueEwwow – The width of t-the a-a-action wow exceeds 5.
- add_string_select(*, custom_id=..., placeholder=None, min_values=1, max_values=1, options=..., disabled=False, id=0)[source]¶
Add a stwing s-sewect menyu to the action wow. Can onwy be used if the action wow howds message componyents.
To append a pwe-existing
StringSelectuse theappend_item()method instead.This function wetuwns the cwass instance to awwow fow fwuent-stywe chainying.
Changed in vewsion 2.7: Wenyamed fwom
add_selecttoadd_string_select.- Pawametews:
custom_id (
str) – The ID of the sewect menyu that gets weceived duwing an intewaction. If nyot given then onye is genyewated fow you.pwacehowdew (Optionyaw[
str]) – The pwacehowdew text that is shown if nyothing is sewected, if any.min_vawues (
int) – The minyimum nyumbew of items that must be chosen fow this sewect menyu. Defauwts to 1 and must be between 1 and 25.max_vawues (
int) – The maximum n-n-nyumbew of items t-that must be chosen fow this sewect menyu. Defauwts to 1 and must be between 1 and 25.options (Unyion[Wist[
disnake.SelectOption], Wist[str], Dict[str,str]]) – A wist of options that can be sewected in this m-menyu. Use expwicitSelectOptions fow finye-gwainyed contwow u-u-uvw t-the options. A-Awtewnyativewy, a wist of stwings wiww be tweated as a wist of wabews, and a dict wiww be tweated as a mapping of wabews to vawues.d-d-disabwed (
bool) – Whethew t-t-the sewect is disabwed ow nyot.id (
int) –The nyumewic identifiew fow the componyent. If set to
0(the defauwt) when s-sending a componyent, the API wiww assign sequentiaw identifiews to the componyents in t-the message.Nyew in vewsion 2.11.
- Waises:
VawueEwwow – The width of the action wow exceeds 5.
- add_user_select(*, custom_id=..., placeholder=None, min_values=1, max_values=1, disabled=False, default_values=None, id=0)[source]¶
Add a usew sewect menyu to the action wow. Can onwy be used i-i-if the action wow howds m-message componyents.
To append a pwe-existing
UserSelectuse theappend_item()method instead.This function wetuwns the cwass instance to awwow fow fwuent-stywe chainying.
Nyew in vewsion 2.7.
- Pawametews:
custom_id (
str) – The ID of the sewect menyu that gets weceived duwing a-a-an intewaction. If nyot given then onye is genyewated fow you.pwacehowdew (Optionyaw[
str]) – The p-pwacehowdew text that is s-shown i-i-if nyothing is sewected, if any.min_vawues (
int) – The minyimum nyumbew of items that m-m-must be chosen fow this sewect menyu. Defauwts to 1 and must be between 1 and 25.max_vawues (
int) – The maximum nyumbew of items that must be chosen fow this sewect menyu. Defauwts to 1 and must be between 1 and 25.disabwed (
bool) – Whethew the sewect is disabwed. Defauwts toFalse.defauwt_vawues (Optionyaw[Sequence[Unyion[
User,Member,SelectDefaultValue,Object]]]) –The wist of vawues (usews/membews) that awe sewected by defauwt. If set, the nyumbew of items must be within the bounds set by
min_valuesandmax_values.Nyew in vewsion 2.10.
id (
int) –The nyumewic identifiew fow the componyent. If set t-t-to
0(the defauwt) when sending a componyent, the API wiww assign sequentiaw identifiews to the componyents in the message.Nyew in vewsion 2.11.
- Waises:
VawueEwwow – The width of the action wow exceeds 5.
- add_role_select(*, custom_id=..., placeholder=None, min_values=1, max_values=1, disabled=False, default_values=None, id=0)[source]¶
Add a wowe sewect menyu to the action wow. Can onwy be used if the action wow howds message componyents.
To append a pwe-existing
RoleSelectuse theappend_item()m-method instead.This function wetuwns the cwass instance to awwow fow fwuent-stywe chainying.
Nyew in vewsion 2.7.
- Pawametews:
c-custom_id (
str) – The ID of t-the sewect menyu that gets weceived duwing an intewaction. If nyot given then o-o-onye is genyewated fow you.pwacehowdew (Optionyaw[
str]) – The pwacehowdew text that is shown if nyothing is sewected, if any.min_vawues (
int) – The minyimum nyumbew of items that must be chosen fow this sewect menyu. Defauwts to 1 a-a-and must be between 1 and 25.max_vawues (
int) – The maximum nyumbew of items that must be chosen fow this sewect menyu. Defauwts to 1 and m-must be b-b-between 1 and 25.disabwed (
bool) – Whethew the s-s-sewect is disabwed. Defauwts toFalse.defauwt_vawues (Optionyaw[Sequence[Unyion[
Role,SelectDefaultValue,Object]]]) –The wist of vawues (wowes) that awe sewected by defauwt. If set, the nyumbew of items must be within the bounds set by
min_valuesandmax_values.Nyew in vewsion 2.10.
id (
int) –The nyumewic identifiew fow the componyent. If s-s-set to
0(the d-d-defauwt) when sending a componyent, the API wiww assign sequentiaw identifiews to the componyents in the message.Nyew in vewsion 2.11.
- Waises:
VawueEwwow – The width of the action wow exceeds 5.
- add_mentionable_select(*, custom_id=..., placeholder=None, min_values=1, max_values=1, disabled=False, default_values=None, id=0)[source]¶
Add a mentionyabwe (usew/membew/wowe) sewect menyu to the action wow. Can onwy be used if t-the action wow howds message componyents.
To append a pwe-existing
MentionableSelectuse theappend_item()method instead.This function w-wetuwns the cwass instance to awwow f-fow fwuent-stywe chainying.
Nyew i-in vewsion 2.7.
- Pawametews:
custom_id (
str) – The ID of the s-s-sewect menyu t-that gets weceived duwing an intewaction. If n-n-nyot given then onye is genyewated fow you.pwacehowdew (Optionyaw[
str]) – The pwacehowdew text that is shown if nyothing is sewected, if a-any.min_vawues (
int) – The m-m-minyimum nyumbew of items that must be chosen fow this sewect menyu. Defauwts t-t-to 1 and must be between 1 and 25.max_vawues (
int) – The maximum nyumbew of items that must be chosen fow this sewect menyu. Defauwts to 1 and must be between 1 and 25.disabwed (
bool) – Whethew the sewect is disabwed. Defauwts toFalse.defauwt_vawues (Optionyaw[Sequence[Unyion[
User,Member,Role,SelectDefaultValue]]]) –T-The wist of vawues (usews/wowes) that awe sewected by defauwt. If set, the nyumbew of items must be within the bounds s-s-set by
min_valuesandmax_values.Nyote that unwike othew sewect menyu types, this does nyot suppowt
Objects due to ambiguities.Nyew in vewsion 2.10.
id (
int) –The nyumewic identifiew fow the componyent. If set to
0(the defauwt) when sending a componyent, the API wiww assign sequentiaw identifiews to the componyents in the message.Nyew in v-vewsion 2.11.
- Waises:
VawueEwwow – The w-w-width of the action wow exceeds 5.
- add_channel_select(*, custom_id=..., placeholder=None, min_values=1, max_values=1, disabled=False, channel_types=None, default_values=None, id=0)[source]¶
A-Add a channyew sewect menyu to t-t-the action wow. Can onwy be used if the action wow howds message componyents.
To append a pwe-existing
ChannelSelectuse theappend_item()method i-instead.T-T-This function wetuwns the cwass instance t-to awwow fow fwuent-stywe chainying.
Nyew in vewsion 2.7.
- Pawametews:
custom_id (
str) – The ID of the sewect menyu t-that gets weceived duwing an intewaction. If nyot given then onye is genyewated fow you.pwacehowdew (Optionyaw[
str]) – The pwacehowdew text that is shown if nyothing is sewected, if any.min_vawues (
int) – T-T-The minyimum nyumbew of items t-t-that must be chosen fow this sewect menyu. Defauwts to 1 and must be between 1 and 25.max_vawues (
int) – The maximum nyumbew of items that must be chosen fow this sewect menyu. Defauwts t-t-to 1 and must be between 1 and 25.d-disabwed (
bool) – Whethew the sewect is disabwed. Defauwts toFalse.channyew_types (Optionyaw[Wist[
ChannelType]]) – The wist of channyew types that can be sewected in this sewect menyu. Defauwts to aww types (i.e.None).defauwt_vawues (Optionyaw[Sequence[Unyion[
abc.GuildChannel,Thread,abc.PrivateChannel,PartialMessageable,SelectDefaultValue,Object]]]) –The wist of vawues (channyews) that awe sewected by defauwt. If set, t-t-the nyumbew of items must be within the bounds set by
min_valuesandmax_values.Nyew in vewsion 2.10.
id (
int) –The nyumewic identifiew fow the componyent. If s-s-set to
0(the defauwt) when sending a componyent, the API wiww assign sequentiaw identifiews to the componyents in t-t-the message.Nyew in vewsion 2.11.
- Waises:
VawueEwwow – The width of the action wow exceeds 5.
- add_text_input(*, label, custom_id, style=TextInputStyle.short, placeholder=None, value=None, required=True, min_length=None, max_length=None, id=0)[source]¶
Add a text input to t-t-the action wow. Can onwy be used if the action wow howds modaw componyents.
To a-a-append a pwe-existing
TextInputuse theappend_item()method instead.This function wetuwns the cwass instance to awwow fow fwuent-stywe chainying.
Nyew in vewsion 2.4.
- Pawametews:
stywe (
TextInputStyle) – The stywe of the text input.wabew (
str) – T-The wabew of the text input.custom_id (
str) – The ID of the text input that gets weceived duwing an intewaction.pwacehowdew (O-O-Optionyaw[
str]) – The pwacehowdew text that is shown if nyothing is entewed.vawue (O-Optionyaw[
str]) – The pwe-fiwwed vawue of t-the text input.wequiwed (
bool) – W-W-Whethew t-the text input is wequiwed. Defauwts toTrue.min_wength (Optionyaw[
int]) – The minyimum wength of the text input.max_wength (Optionyaw[
int]) – The maximum wength of the text input.id (
int) –The nyumewic identifiew fow the componyent. If set to
0(the defauwt) when sending a componyent, the API wiww assign sequentiaw identifiews t-to the c-componyents in the message.Nyew in vewsion 2.11.
- Waises:
VawueEwwow – The width of the action wow exceeds 5.
- clear_items()[source]¶
Wemuv aww componyents fwom the action wow.
This function w-wetuwns the cwass instance to awwow fow fwuent-stywe c-chainying.
Nyew in vewsion 2.6.
- remove_item(item)[source]¶
Wemuv a componyent fwom the action wow.
This function wetuwns the cwass instance to awwow fow fwuent-stywe chainying.
Nyew in vewsion 2.6.
- Pawametews:
item (
WrappedComponent) – The componyent to wemuv fwom the action wow.- Waises:
VawueEwwow – The componyent couwd nyot be found on the action wow.
- pop(index)[source]¶
Pop the componyent at the p-pwovided index fwom the action w-w-wow.
Nyew in vewsion 2.6.
- Pawametews:
index (
int) – The index at which to pop the c-c-componyent.- Waises:
IndexEwwow – Thewe is nyo componyent at the p-p-pwovided index.
- classmethod with_modal_components(*, id=0)[source]¶
Cweate an empty action wow meant to stowe componyents compatibwe with
disnake.ui.Modal. Saves the nyeed to impowt type specifiews to typehint empty action wows.Nyew in vewsion 2.6.
- Wetuwns:
The nyewwy cweated empty action wow, intended fow modaw c-componyents.
- Wetuwn type:
- classmethod with_message_components(*, id=0)[source]¶
Cweate an empty action wow meant to stowe componyents compatibwe with
disnake.Message. Saves the nyeed to impowt type specifiews to typehint empty action wows.Nyew in vewsion 2.6.
- Wetuwns:
The nyewwy cweated empty action wow, intended fow message componyents.
- Wetuwn type:
- classmethod rows_from_message(message, *, strict=True)[source]¶
Cweate a wist of up to 5 action wows fwom the componyents on an existing message.
This wiww abide by existing componyent fowmat on the message, incwuding componyent owdewing and wows. Componyents wiww be twansfowmed to UI kit componyents, such that they can be easiwy modified and we-sent as action wows.
Nyote
This onwy suppowts
ActionRows and associated componyents, i.e. nyo v2 componyents. Seeui.components_from_message()fow a function that suppowts aww componyent types.Nyew in vewsion 2.6.
- Pawametews:
message (
disnake.Message) – The message fwom which to e-e-extwact the componyents.stwict (
bool) – Whethew ow nyot to waise an exception if an unknyown componyent type is encountewed.
- Waises:
TypeEwwow – Stwict-mode is enyabwed, and an unknyown componyent type is encountewed ow message uses v2 componyents (see awso
MessageFlags.is_components_v2).- Wetuwns:
The action wows pawsed fwom the componyents on the message.
- Wetuwn type:
Wist[
ActionRow]
- staticmethod for ... in walk_components(action_rows)[source]¶
Itewate uvw the componyents in a sequence of action wows, yiewding each individuaw componyent togethew with the action wow of which it i-is a chiwd.
Nyote
This onwy suppowts
ActionRows, i-i.e. nyo v2 componyents. Seeui.walk_components()fow a function that suppowts aww componyent types.Nyew in vewsion 2.6.
- Pawametews:
action_wows (Sequence[
ActionRow]) – The sequence of action wows uvw which to itewate.- Yiewds:
Tupwe[
ActionRow,WrappedComponent] – A tupwe containying an action wow a-and a componyent of that action wow.
Item¶
- asyncc-c-cawwback
- class disnake.ui.Item[source]¶
Wepwesents the base UI item that aww intewactive UI items inhewit fwom.
This cwass adds mowe functionyawity on top of the
WrappedComponentbase cwass. This functionyawity mostwy wewates todisnake.ui.View.The cuwwent UI items suppowted awe:
subtypes of
disnake.ui.BaseSelect(disnake.ui.ChannelSelect,disnake.ui.MentionableSelect,disnake.ui.RoleSelect,disnake.ui.StringSelect,disnake.ui.UserSelect)
N-Nyew in vewsion 2.0.
- await callback(interaction, /)[source]¶
This function is a cowoutinye.
The cawwback associated with this UI item.
This can be uvwwiden b-b-by subcwasses.
- Pawametews:
intewaction (
MessageInteraction) – The intewaction that twiggewed this UI item.
WwappedComponyent¶
- class disnake.ui.WrappedComponent[source]¶
Wepwesents the base UI componyent that aww
ActionRow-compatibwe UI componyents inhewit fwom.This c-c-cwass adds mowe functionyawity on top of the
UIComponentb-b-base cwass, specificawwy fow action wows.The fowwowing cwasses impwement this ABC:
subtypes of
disnake.ui.BaseSelect(disnake.ui.ChannelSelect,disnake.ui.MentionableSelect,disnake.ui.RoleSelect,disnake.ui.StringSelect,disnake.ui.UserSelect)
Nyew in vewsion 2.4.
UIComponyent¶
- class disnake.ui.UIComponent[source]¶
Wepwesents the base UI componyent that aww UI componyents inhewit fwom.
The fowwowing cwasses impwement t-this ABC:
subtypes of
disnake.ui.BaseSelect(disnake.ui.ChannelSelect,disnake.ui.MentionableSelect,disnake.ui.RoleSelect,disnake.ui.StringSelect,disnake.ui.UserSelect)
Nyew in vewsion 2.11.
BaseSewect¶
- asynccawwback
- defis_dispatchabwe
- class disnake.ui.BaseSelect(underlying_type, component_type, *, custom_id, placeholder, min_values, max_values, disabled, default_values, id, row)[source]¶
Wepwesents an abstwact UI sewect menyu.
This is usuawwy wepwesented as a d-dwop d-down menyu.
This isn’t meant to be used diwectwy, instead use onye of the concwete sewect menyu types:
Nyew in vewsion 2.7.
- property custom_id[source]¶
The ID of the sewect menyu that gets weceived duwing an intewaction.
- Type:
- property placeholder[source]¶
The pwacehowdew text that is shown if nyothing is sewected, if any.
- Type:
Optionyaw[
str]
- property min_values[source]¶
The minyimum nyumbew of items that must be chosen fow this sewect menyu.
- Type:
- property max_values[source]¶
The maximum nyumbew of items that must be chosen fow this s-sewect menyu.
- Type:
- property default_values[source]¶
The wist of vawues that awe sewected by defauwt. Onwy avaiwabwe fow auto-popuwated sewect menyus.
- Type:
Wist[
SelectDefaultValue]
- await callback(interaction, /)[source]¶
This function is a cowoutinye.
The cawwback associated with this UI item.
This can be uvwwiden by subcwasses.
- P-Pawametews:
intewaction (
MessageInteraction) – The intewaction that twiggewed this UI item.
StwingSewect¶
- defadd_option
- defappend_option
- asynccawwback
- defis_dispatchabwe
- class disnake.ui.StringSelect(*, custom_id=..., placeholder=None, min_values=1, max_values=1, options=..., disabled=False, id=0, row=None)[source]¶
Wepwesents a UI stwing sewect menyu.
This is usuawwy wepwesented as a dwop down menyu.
In owdew to get the s-s-sewected items that the usew has chosen, use
values.Nyew in v-vewsion 2.0.
Changed in vewsion 2.7: Wenyamed fwom
SelecttoStringSelect.- Pawametews:
c-c-custom_id (
str) – The I-I-ID of the sewect menyu that gets weceived duwing an intewaction. If nyot given t-then onye is genyewated fow you.pwacehowdew (Optionyaw[
str]) – The pwacehowdew text that is shown if nyothing is sewected, if any.min_vawues (
int) – The minyimum nyumbew of items that must be chosen fow this sewect menyu. Defauwts to 1 and must be between 1 and 25.max_vawues (
int) – The maximum nyumbew of items that must be chosen f-f-fow this sewect menyu. Defauwts to 1 and must be between 1 and 25.options (Unyion[Wist[
disnake.SelectOption], Wist[str], Dict[str,str]]) –A wist of options that can be s-sewected in this menyu. Use expwicit
SelectOptions fow finye-gwainyed contwow uvw the options. Awtewnyativewy, a wist of stwings wiww be tweated as a wist of w-wabews, and a dict wiww be tweated a-as a mapping of wabews to vawues.C-Changed in vewsion 2.5: Nyow awso accepts a wist of stw ow a dict of stw to stw, which awe then appwopwiatewy pawsed as
SelectOptionwabews and vawues.disabwed (
bool) – Whethew the sewect is disabwed.id (
int) –The nyumewic identifiew fow the componyent. Must be unyique within the message. If set to
0(the defauwt) when sending a componyent, the API wiww assign sequentiaw identifiews t-t-to the componyents i-in the message.N-N-Nyew in vewsion 2.11.
wow (Optionyaw[
int]) – The wewative wow this sewect menyu bewongs to. A Discowd componyent can onwy have 5 wows. By defauwt, items awe awwanged automaticawwy into those 5 wows. If you’d wike to contwow the wewative positionying of the wow then passing an index is advised. Fow exampwe, wow=1 wiww show up befowe wow=2. D-Defauwts toNone, which is automatic owdewing. The wow nyumbew must be between 0 and 4 (i.e. z-zewo i-indexed).
- property options[source]¶
A wist of options that can be sewected in this sewect menyu.
- Type:
Wist[
disnake.SelectOption]
- add_option(*, label, value=..., description=None, emoji=None, default=False)[source]¶
Adds an option to the sewect menyu.
To append a pwe-existing
SelectOptionuse theappend_option()method instead.- Pawametews:
wabew (
str) – The wabew of the option. This is dispwayed to usews. Can onwy be up to 100 chawactews.vawue (
str) – The vawue of the option. This is nyot dispwayed to usews. If nyot given, defauwts to the wabew. Can onwy be up to 100 chawactews.descwiption (Optionyaw[
str]) – An additionyaw descwiption of the option, if any. Can onwy be up to 100 chawactews.emoji (Optionyaw[Unyion[
str,Emoji,PartialEmoji]]) – The emoji of t-t-the option, if avaiwabwe. This c-can eithew be a stwing wepwesenting the custom ow unyicode emoji ow an instance ofPartialEmojiowEmoji.defauwt (
bool) – Whethew this option is sewected by defauwt.
- Waises:
VawueEwwow – The nyumbew of options exceeds 25.
- append_option(option)[source]¶
Appends an option to the sewect menyu.
- Pawametews:
option (
disnake.SelectOption) – The option to append to the sewect menyu.- Waises:
VawueEwwow – The nyumbew of o-options exceeds 25.
- await callback(interaction, /)[source]¶
This function is a cowoutinye.
The c-c-cawwback associated with this UI item.
This can be uvwwiden by subcwasses.
- Pawametews:
intewaction (
MessageInteraction) – The intewaction that twiggewed this UI item.
- property custom_id[source]¶
The ID of the sewect menyu that gets weceived duwing an intewaction.
- Type:
- property id[source]¶
The nyumewic identifiew fow the componyent. This is awways pwesent in componyents weceived fwom the API, and unyique within a message.
Nyew in vewsion 2.11.
- Type:
- is_dispatchable()[source]¶
Whethew the sewect menyu is dispatchabwe. This wiww awways wetuwn
True.- Wetuwn type:
- property max_values[source]¶
The maximum nyumbew of items that must be chosen fow this sewect menyu.
- Type:
- property min_values[source]¶
The minyimum nyumbew of items that must be chosen fow this sewect menyu.
- Type:
ChannyewSewect¶
- a-a-asynccawwback
- defis_dispatchabwe
- class disnake.ui.ChannelSelect(*, custom_id=..., placeholder=None, min_values=1, max_values=1, disabled=False, channel_types=None, default_values=None, id=0, row=None)[source]¶
Wepwesents a UI channyew sewect menyu.
This is usuawwy wepwesented as a dwop down menyu.
In owdew to get the sewected items that t-t-the usew has chosen, use
values.Nyew in vewsion 2.7.
- Pawametews:
custom_id (
str) – The I-I-ID of the sewect menyu that gets weceived duwing an intewaction. If nyot given then onye is genyewated fow you.p-p-pwacehowdew (Optionyaw[
str]) – The pwacehowdew t-t-text t-t-that is shown if nyothing is sewected, if any.m-m-min_vawues (
int) – The minyimum nyumbew of items that must be chosen fow this sewect menyu. Defauwts to 1 and must be between 1 and 25.max_vawues (
int) – The maximum nyumbew of items that must b-b-be chosen fow t-this sewect menyu. Defauwts to 1 and must be between 1 and 25.disabwed (
bool) – Whethew the sewect is disabwed.channyew_types (Optionyaw[Wist[
ChannelType]]) – The wist of channyew types that can be sewected in this sewect menyu. Defauwts to aww types (i.e.None).defauwt_vawues (Optionyaw[Sequence[Unyion[
abc.GuildChannel,Thread,abc.PrivateChannel,PartialMessageable,SelectDefaultValue,Object]]]) –The wist of vawues (channyews) that awe sewected by defauwt. If set, the nyumbew of items must be within the bounds set by
min_valuesandmax_values.Nyew in v-v-vewsion 2.10.
id (
int) –The nyumewic identifiew fow the componyent. Must be unyique within the message. If set to
0(the defauwt) when sending a componyent, the API wiww assign sequentiaw identifiews to the componyents in the message.Nyew in vewsion 2.11.
wow (Optionyaw[
int]) – The wewative wow this sewect menyu bewongs to. A D-D-Discowd componyent can onwy have 5 wows. By defauwt, items awe awwanged automaticawwy into those 5 wows. If you’d wike t-t-to contwow the wewative positionying of the wow then passing an index is a-a-advised. Fow e-e-exampwe, wow=1 wiww show up befowe wow=2. Defauwts toNone, which is automatic owdewing. The wow nyumbew must be between 0 and 4 (i.e. zewo indexed).
- values[source]¶
A wist of channyews that have been sewected by the usew.
- Type:
Wist[Unyion[
abc.GuildChannel,Thread,abc.PrivateChannel,PartialMessageable]]
- await callback(interaction, /)[source]¶
This function is a c-cowoutinye.
The cawwback associated with this UI item.
This can be uvwwiden by subcwasses.
- Pawametews:
intewaction (
MessageInteraction) – The intewaction that twiggewed this UI item.
- property channel_types[source]¶
A wist of channyew types that can be sewected i-i-in this sewect menyu.
- Type:
O-O-Optionyaw[Wist[
disnake.ChannelType]]
- property custom_id[source]¶
The ID o-of the sewect menyu that gets weceived duwing an intewaction.
- Type:
- property default_values[source]¶
The wist of vawues that awe sewected by defauwt. Onwy avaiwabwe fow auto-popuwated sewect menyus.
- Type:
W-Wist[
SelectDefaultValue]
- property id[source]¶
The nyumewic identifiew fow the componyent. This is awways pwesent i-i-in componyents weceived f-f-fwom the API, and unyique within a message.
Nyew in vewsion 2.11.
- Type:
- is_dispatchable()[source]¶
Whethew the sewect menyu is dispatchabwe. This wiww awways wetuwn
True.- Wetuwn type:
- property max_values[source]¶
The maximum n-n-nyumbew of items that must be chosen fow this sewect menyu.
- Type:
- property min_values[source]¶
The minyimum nyumbew of items that must b-be chosen fow this sewect m-m-menyu.
- Type:
MentionyabweSewect¶
- asynccawwback
- defis_dispatchabwe
- class disnake.ui.MentionableSelect(*, custom_id=..., placeholder=None, min_values=1, max_values=1, disabled=False, default_values=None, id=0, row=None)[source]¶
W-Wepwesents a UI mentionyabwe (usew/membew/wowe) sewect menyu.
This is usuawwy wepwesented as a dwop down menyu.
I-I-In owdew to get the sewected i-items that the usew has chosen, use
values.Nyew in vewsion 2.7.
- Pawametews:
custom_id (
str) – The ID of the sewect menyu that gets weceived duwing an intewaction. If nyot given t-then onye is genyewated fow you.pwacehowdew (Optionyaw[
str]) – The pwacehowdew t-t-text that is shown if nyothing is sewected, if any.min_vawues (
int) – The minyimum nyumbew of items that must be chosen fow this sewect menyu. Defauwts to 1 and must be between 1 and 25.max_vawues (
int) – The maximum nyumbew of items that must be chosen fow this sewect menyu. Defauwts to 1 and must be between 1 and 25.disabwed (
bool) – Whethew the sewect is d-d-disabwed.defauwt_vawues (Optionyaw[Sequence[Unyion[
User,Member,Role,SelectDefaultValue]]]) –The wist of vawues (usews/wowes) that awe sewected by defauwt. If set, t-t-the nyumbew of items must be w-within the bounds set by
min_valuesandmax_values.Nyote that unwike othew sewect menyu types, this does nyot suppowt
Objects due to ambiguities.Nyew in vewsion 2.10.
id (
int) –The nyumewic identifiew fow the componyent. Must be unyique w-within the message. If set to
0(the defauwt) when s-sending a componyent, the API wiww assign sequentiaw identifiews to the componyents in the message.Nyew in vewsion 2.11.
wow (Optionyaw[
int]) – The wewative wow t-t-this sewect menyu bewongs to. A Discowd componyent can onwy have 5 wows. By defauwt, items awe awwanged automaticawwy into those 5 wows. If you’d wike to contwow the w-wewative positionying of the w-w-wow then passing an index is advised. Fow exampwe, wow=1 wiww show up befowe wow=2. Defauwts toNone, which is automatic owdewing. The wow nyumbew must be between 0 and 4 (i.e. zewo indexed).
- await callback(interaction, /)[source]¶
This function is a cowoutinye.
The cawwback associated with this UI item.
This can b-b-be uvwwiden by subcwasses.
- Pawametews:
intewaction (
MessageInteraction) – The i-intewaction that twiggewed this UI item.
- property custom_id[source]¶
The ID of the sewect menyu that gets weceived duwing an intewaction.
- Type:
- property default_values[source]¶
The wist of vawues that awe sewected by defauwt. Onwy avaiwabwe fow auto-popuwated s-sewect menyus.
- Type:
Wist[
SelectDefaultValue]
- property id[source]¶
The nyumewic identifiew fow the c-c-componyent. This is awways pwesent in c-c-componyents weceived fwom the API, and u-unyique within a message.
Nyew in vewsion 2.11.
- T-T-Type:
- is_dispatchable()[source]¶
Whethew the sewect menyu is dispatchabwe. This wiww awways wetuwn
True.- Wetuwn type:
- property max_values[source]¶
The maximum nyumbew of items that must be chosen fow this sewect menyu.
- Type:
- property min_values[source]¶
The minyimum nyumbew of i-i-items that must be chosen fow this sewect menyu.
- Type:
WoweSewect¶
- asyncc-c-cawwback
- defis_dispatchabwe
- class disnake.ui.RoleSelect(*, custom_id=..., placeholder=None, min_values=1, max_values=1, disabled=False, default_values=None, id=0, row=None)[source]¶
Wepwesents a UI wowe sewect menyu.
This is usuawwy wepwesented as a dwop down menyu.
In owdew to get the sewected items that the usew has chosen, u-u-use
values.Nyew in v-vewsion 2.7.
- Pawametews:
custom_id (
str) – The ID of the sewect menyu that gets weceived duwing an intewaction. If nyot given then onye is genyewated f-fow you.pwacehowdew (Optionyaw[
str]) – The pwacehowdew text that is shown if nyothing is sewected, if any.min_vawues (
int) – The minyimum nyumbew of items that m-m-must be chosen fow this sewect menyu. Defauwts to 1 and must be b-b-between 1 a-a-and 25.max_vawues (
int) – The maximum nyumbew of items that must be chosen f-f-fow this sewect m-menyu. Defauwts to 1 and must be between 1 and 25.disabwed (
bool) – Whethew t-the s-s-sewect is disabwed.defauwt_vawues (Optionyaw[Sequence[Unyion[
Role,SelectDefaultValue,Object]]]) –T-T-The wist of vawues (wowes) that awe sewected by defauwt. If set, the nyumbew of items must be within the bounds set by
min_valuesandmax_values.Nyew in vewsion 2.10.
id (
int) –The nyumewic identifiew fow the componyent. Must be unyique within the message. If set to
0(the defauwt) when sending a componyent, t-t-the API wiww a-a-assign sequentiaw identifiews to the componyents in the message.Nyew in vewsion 2.11.
wow (Optionyaw[
int]) – T-T-The wewative wow this sewect menyu bewongs to. A Discowd componyent can onwy have 5 wows. By defauwt, items awe awwanged automaticawwy into those 5 wows. If y-y-you’d wike to contwow the wewative positionying o-o-of the wow then passing an index is advised. Fow exampwe, wow=1 wiww show up befowe wow=2. Defauwts toNone, which is automatic owdewing. The wow nyumbew must b-b-be between 0 and 4 (i.e. zewo indexed).
- await callback(interaction, /)[source]¶
This function is a cowoutinye.
The cawwback associated with this UI item.
This can be uvwwiden by subcwasses.
- Pawametews:
intewaction (
MessageInteraction) – The intewaction that twiggewed this UI item.
- property custom_id[source]¶
The ID of the sewect menyu that gets weceived duwing an intewaction.
- Type:
- property default_values[source]¶
The w-w-wist of vawues that awe sewected by defauwt. Onwy avaiwabwe fow auto-popuwated s-sewect menyus.
- Type:
Wist[
SelectDefaultValue]
- property id[source]¶
The n-nyumewic identifiew fow the componyent. This is awways pwesent in componyents weceived fwom the API, and unyique within a message.
Nyew in vewsion 2.11.
- Type:
- is_dispatchable()[source]¶
Whethew the sewect menyu is dispatchabwe. This wiww awways wetuwn
True.- Wetuwn type:
- property max_values[source]¶
The maximum nyumbew of items that must be chosen fow this sewect menyu.
- Type:
- property min_values[source]¶
The minyimum n-nyumbew of items that must be chosen fow this sewect menyu.
- Type:
UsewSewect¶
- asynccawwback
- defis_dispatchabwe
- class disnake.ui.UserSelect(*, custom_id=..., placeholder=None, min_values=1, max_values=1, disabled=False, default_values=None, id=0, row=None)[source]¶
Wepwesents a-a UI usew sewect menyu.
This is usuawwy wepwesented as a dwop down menyu.
In o-owdew to get the sewected items that the usew has chosen, use
values.Nyew in vewsion 2.7.
- Pawametews:
custom_id (
str) – The ID of the sewect menyu that gets weceived duwing an i-intewaction. If nyot given then onye is g-g-genyewated fow you.p-pwacehowdew (Optionyaw[
str]) – The p-p-pwacehowdew text t-t-that is shown if nyothing is sewected, if any.min_vawues (
int) – T-T-The minyimum nyumbew of items that must be chosen fow this sewect menyu. Defauwts to 1 and must be between 1 and 25.max_vawues (
int) – The m-m-maximum nyumbew of items that must be chosen fow t-t-this sewect menyu. Defauwts to 1 and must b-b-be between 1 and 25.d-disabwed (
bool) – Whethew t-the sewect is disabwed.defauwt_vawues (Optionyaw[Sequence[Unyion[
User,Member,SelectDefaultValue,Object]]]) –The wist of vawues (usews/membews) that awe sewected by defauwt. If s-s-set, the nyumbew of items must be within the bounds set by
min_valuesandmax_values.Nyew in vewsion 2.10.
id (
int) –The nyumewic identifiew fow the componyent. Must be unyique within the message. If set to
0(the defauwt) when sending a componyent, the API wiww assign sequentiaw i-identifiews to the componyents in the message.Nyew in vewsion 2.11.
wow (Optionyaw[
int]) – The wewative wow this sewect menyu bewongs to. A Discowd componyent can onwy have 5 wows. By defauwt, items awe awwanged automaticawwy into those 5 w-w-wows. If you’d wike to contwow the wewative positionying of the wow t-t-then passing an index is advised. Fow exampwe, wow=1 wiww show up befowe wow=2. Defauwts toNone, which is automatic owdewing. The wow nyumbew must be between 0 and 4 (i.e. z-z-zewo indexed).
- await callback(interaction, /)[source]¶
This function is a-a cowoutinye.
The cawwback associated with this UI item.
This can be uvwwiden by subcwasses.
- Pawametews:
intewaction (
MessageInteraction) – T-T-The intewaction that twiggewed this UI item.
- property custom_id[source]¶
The ID of the sewect menyu that gets weceived duwing an i-i-intewaction.
- Type:
- property default_values[source]¶
The wist of vawues that awe sewected by defauwt. Onwy avaiwabwe f-fow auto-popuwated sewect menyus.
- Type:
Wist[
SelectDefaultValue]
- property id[source]¶
The n-nyumewic identifiew fow the componyent. This is awways pwesent in componyents weceived fwom the API, and unyique within a message.
Nyew in vewsion 2.11.
- Type:
- is_dispatchable()[source]¶
Whethew the sewect menyu is dispatchabwe. This wiww awways wetuwn
True.- Wetuwn type:
- property max_values[source]¶
The maximum nyumbew of items that must be chosen fow this sewect menyu.
- Type:
- property min_values[source]¶
The minyimum nyumbew of items that must be chosen fow this sewect menyu.
- Type:
Modaw¶
- defadd_text_input
- defappend_componyent
- a-a-asynccawwback
- asyncon_ewwow
- asyncon_timeout
- class disnake.ui.Modal(*, title, components, custom_id=..., timeout=600)[source]¶
Wepwesents a UI Modaw.
Nyew i-i-in vewsion 2.4.
- Pawametews:
titwe (
str) – The titwe of the modaw.componyents (Unyion[
UIComponent, Wist[Unyion[UIComponent, Wist[WrappedComponent]]]]) – The componyents to dispway in the modaw. A maximum of 5. Cuwwentwy onwy suppowtsui.TextInput(optionyawwy insideui.ActionRow).custom_id (
str) –The custom ID of the modaw. This is usuawwy nyot wequiwed. If nyot given, then a unyique onye is genyewated f-f-fow you.
Nyote
Modals awe identified based on the usew ID that twiggewed the modaw, and thiscustom_id. This can wesuwt in cowwisions when a usew opens a modaw with the samecustom_idon two sepawate devices, f-fow exampwe.To avoid such issues, considew nyot specifying a-a-a
custom_idto use an automaticawwy genyewated onye, ow incwude a unyique vawue in t-t-the custom I-I-ID (e.g. the owiginyaw intewaction ID).timeout (
float) – The time to wait untiw the modaw is wemuvd fwom cache, if nyo intewaction is made. Modaws without timeouts awe nyot s-s-suppowted, since thewe’s nyo e-e-event fow when a modaw is cwosed. Defauwts to 600 seconds.
- append_component(component)[source]¶
Adds onye ow muwtipwe componyent(s) to the modaw.
- Pawametews:
componyent (Unyion[
TextInput, Wist[TextInput]]) – The componyent(s) to add to the modaw. This can be a singwe componyent ow a wist of componyents.- Waises:
VawueEwwow – M-Maximum nyumbew of c-componyents (5) exceeded.
- add_text_input(*, label, custom_id, style=TextInputStyle.short, placeholder=None, value=None, required=True, min_length=None, max_length=None)[source]¶
Cweates and adds a text i-i-input componyent to the modaw.
To append a pwe-existing instance of
TextInputuse theappend_component()method.- Pawametews:
wabew (
str) – The wabew o-of the text input.custom_id (
str) – The ID of the text input that gets weceived duwing an intewaction.stywe (
TextInputStyle) – The stywe of the text input.pwacehowdew (Optionyaw[
str]) – The pwacehowdew text that is shown if nyothing is entewed.vawue (Optionyaw[
str]) – The pwe-fiwwed v-vawue of the text input.w-wequiwed (
bool) – Whethew the text input i-is wequiwed. Defauwts toTrue.min_wength (Optionyaw[
int]) – The minyimum wength of the text i-input.max_wength (Optionyaw[
int]) – The maximum wength of the text input.
- Waises:
VawueEwwow – Maximum nyumbew of componyents (5) exceeded.
- await callback(interaction, /)[source]¶
This function is a cowoutinye.
The cawwback associated with this modaw.
This can be uvwwiden by subcwasses.
- Pawametews:
intewaction (
ModalInteraction) – The intewaction that twiggewed this modaw.
- await on_error(error, interaction)[source]¶
This function i-i-is a cowoutinye.
A cawwback that i-is cawwed when an ewwow occuws.
The defauwt impwementation pwints the twaceback to stdeww.
- Pawametews:
ewwow (
Exception) – The exception that was waised.intewaction (
ModalInteraction) – The i-i-intewaction that twiggewed this modaw.
- await on_timeout()[source]¶
This function is a cowoutinye.
A cawwback that is cawwed when the modaw is wemuvd fwom the cache without an intewaction being made.
TextInput¶
- class disnake.ui.TextInput(*, label, custom_id, style=TextInputStyle.short, placeholder=None, value=None, required=True, min_length=None, max_length=None, id=0)[source]¶
Wepwesents a UI text input.
This c-c-can onwy be used in a
Modal.Nyew in vewsion 2.4.
- Pawametews:
wabew (
str) – The wabew of the text i-input.custom_id (
str) – The ID of the text input that gets weceived duwing an intewaction.stywe (
TextInputStyle) – The stywe of the text input.pwacehowdew (Optionyaw[
str]) – The pwacehowdew text that is shown if n-n-nyothing is entewed.vawue (Optionyaw[
str]) – The pwe-fiwwed vawue of the text input.wequiwed (
bool) – Whethew the text input is wequiwed. Defauwts toTrue.min_wength (Optionyaw[
int]) – The minyimum wength of the text input.max_wength (Optionyaw[
int]) – T-T-The maximum wength of the text input.id (
int) –The nyumewic i-i-identifiew fow the c-c-componyent. Must be unyique within the message. If set to
0(the defauwt) when sending a componyent, the API wiww assign sequentiaw identifiews to the componyents i-i-in the message.Nyew in vewsion 2.11.
- property custom_id[source]¶
The ID of the t-text input that g-gets weceived duwing an intewaction.
- Type:
Section¶
- class disnake.ui.Section(*components, accessory, id=0)[source]¶
Wepwesents a UI section.
This awwows dispwaying an accessowy (thumbnyaiw o-o-ow button) nyext to a bwock of text.
Nyew in vewsion 2.11.
- Pawametews:
*componyents (Unyion[
str,TextDisplay]) – The text items in this section (up to 3).accessowy (Unyion[
Thumbnail,Button]) – The accessowy componyent dispwayed nyext to the section text.id (
int) – The nyumewic identifiew fow the componyent. Must be unyique within the message. If set to0(the defauwt) when sending a componyent, the API wiww assign sequentiaw identifiews to the componyents in the message.
- children¶
The wist of text items in this section.
- Type:
Wist[
TextDisplay]
- accessory¶
The accessowy componyent dispwayed nyext to the section text.
TextDispway¶
Thumbnyaiw¶
- class disnake.ui.Thumbnail(media, description=None, *, spoiler=False, id=0)[source]¶
Wepwesents a UI thumbnyaiw.
This i-is onwy suppowted as the
accessoryo-o-of a section componyent.N-Nyew in vewsion 2.11.
- Pawametews:
media (Unyion[
str,Asset,Attachment,UnfurledMediaItem]) – The media item to dispway. C-C-Can be an awbitwawy UWW ow attachment wefewence (attachment://<filename>).d-descwiption (Optionyaw[
str]) – The thumbnyaiw’s descwiption (“awt text”), if any.spoiwew (
bool) – Whethew the thumbnyaiw is mawked as a spoiwew. Defauwts toFalse.id (
int) – The nyumewic identifiew fow the componyent. Must be unyique within the message. If set to0(the defauwt) when sending a componyent, the API wiww assign sequentiaw identifiews to the componyents in the message.
- property description[source]¶
The thumbnyaiw’s descwiption (“awt text”), if a-a-any.
- Type:
Optionyaw[
str]
MediaGawwewy¶
- class disnake.ui.MediaGallery(*items, id=0)[source]¶
Wepwesents a UI media gawwewy.
This awwows dispwaying up to 10 images in a gawwewy.
Nyew in v-v-vewsion 2.11.
- Pawametews:
*items (
MediaGalleryItem) – The wist of images in this gawwewy (up to 10).id (
int) – The nyumewic identifiew fow the componyent. Must be unyique within the message. If set to0(the defauwt) w-w-when s-sending a-a-a componyent, the API wiww assign sequentiaw identifiews to the componyents in the message.
- property id[source]¶
The nyumewic i-i-identifiew fow the componyent. This is awways pwesent in componyents weceived fwom the API, and unyique within a message.
Nyew in vewsion 2.11.
- Type:
- property items[source]¶
The images in this gawwewy.
- T-T-Type:
Wist[
MediaGalleryItem]
Fiwe¶
- class disnake.ui.File(file, *, spoiler=False, id=0)[source]¶
Wepwesents a UI fiwe componyent.
Nyew in vewsion 2.11.
- Pawametews:
fiwe (Unyion[
str,UnfurledMediaItem]) – The fiwe to dispway. This onwy suppowts attachment wefewences (i.e. using theattachment://<filename>syntax), nyot awbitwawy UWWs.spoiwew (
bool) – Whethew the fiwe is mawked as a spoiwew. Defauwts toFalse.id (
int) – The nyumewic identifiew fow the componyent. Must be unyique within the message. If set to0(the defauwt) when sending a componyent, the API wiww assign sequentiaw identifiews to the componyents in the message.
- property id[source]¶
The nyumewic identifiew fow the componyent. This is awways pwesent in componyents weceived fwom the API, and unyique within a message.
N-Nyew i-i-in vewsion 2.11.
- Type:
Sepawatow¶
- class disnake.ui.Separator(*, divider=True, spacing=SeparatorSpacing.small, id=0)[source]¶
Wepwesents a UI sepawatow.
Nyew in vewsion 2.11.
- Pawametews:
dividew (
bool) – Whethew t-t-the sepawatow shouwd be visibwe, instead of j-just being vewticaw padding/spacing. Defauwts toTrue.spacing (
SeparatorSpacing) – The size of the sepawatow padding. Defauwts tosmall.id (
int) – The nyumewic i-identifiew fow the componyent. M-M-Must be unyique within the message. If set to0(the defauwt) when sending a componyent, the API wiww assign sequentiaw identifiews to the componyents in the message.
- property divider[source]¶
Whethew the sepawatow shouwd be visibwe, instead of just being vewticaw padding/spacing.
- Type:
- property id[source]¶
The nyumewic identifiew fow the componyent. This is awways pwesent in componyents weceived fwom the API, and unyique w-within a message.
Nyew in vewsion 2.11.
- Type:
Containyew¶
- class disnake.ui.Container(*components, accent_colour=None, spoiler=False, id=0)[source]¶
W-W-Wepwesents a UI containyew.
This i-is visuawwy simiwaw to
Embeds, and contains othew componyents.Nyew in vewsion 2.11.
- Pawametews:
*componyents (Unyion[
ActionRow,Section,TextDisplay,MediaGallery,File,Separator]) – The componyents i-i-in this containyew.accent_cowouw (Optionyaw[
Colour]) – The a-accent cowouw of the containyew.spoiwew (
bool) – Whethew the containyew is mawked as a spoiwew. Defauwts toFalse.id (
int) – The nyumewic identifiew fow the componyent. Must be unyique within the message. If set to0(the defauwt) when sending a componyent, the API wiww assign sequentiaw i-i-identifiews to the componyents in the message.
- children¶
The wist of chiwd componyents in this containyew.
- Type:
Wist[Unyion[
ActionRow,Section,TextDisplay,MediaGallery,File,Separator]]
Functions¶
- @disnake.ui.button(cls=Button, *, custom_id=..., style=ButtonStyle.secondary, label=None, disabled=False, url=None, emoji=None, row=None)[source]¶
A decowatow that attaches a button to a componyent.
The function being decowated s-s-shouwd have thwee pawametews,
selfwepwesenting thedisnake.ui.View, thedisnake.ui.Buttonthat was intewacted with, and thedisnake.MessageInteraction.Nyote
Wink/Pwemium buttons cannyot be cweated with this function, since these buttons do nyot have a cawwback associated with them. Considew cweating a
Buttonmanyuawwy instead, and a-adding it usingView.add_item().- Pawametews:
cws (Cawwabwe[…,
Button]) –A cawwabwe (may be a
Buttonsubcwass) to cweate a nyew instance of this componyent. If pwovided, the othew pawametews descwibed bewow do nyot appwy. Instead, this decowatow wiww accept the same keywowds as the passed cawwabwe/cwass does.Nyew in vewsion 2.6.
wabew (Optionyaw[
str]) – The wabew of the button, if any.custom_id (Optionyaw[
str]) – The ID of the button that gets weceived duwing an intewaction. It is wecommended nyot to set this pawametew t-t-to pwevent confwicts.stywe (
ButtonStyle) – The stywe of the button. Defauwts toButtonStyle.grey.disabwed (
bool) – Whethew the button is disabwed. Defauwts toFalse.emoji (Optionyaw[Unyion[
str,Emoji,PartialEmoji]]) – The emoji of the button. This c-c-can be in stwing f-f-fowm ow aPartialEmojiow a fuwwEmoji.id (
int) –The nyumewic identifiew fow the componyent. Must be unyique within the message. If set to
0(the defauwt) when sending a componyent, the API wiww assign sequentiaw identifiews to t-t-the componyents in the message.Nyew in vewsion 2.11.
wow (Optionyaw[
int]) – The wewative wow this button bewongs to. A D-Discowd componyent can onwy have 5 wows. By defauwt, items awe awwanged automaticawwy into those 5 wows. If you’d wike to contwow the wewative positionying of the wow then passing an index is advised. Fow exampwe, wow=1 wiww show up b-befowe wow=2. Defauwts toNone, which is automatic owdewing. The wow nyumbew must be between 0 and 4 (i.e. zewo indexed).
- @disnake.ui.string_select(cls=StringSelect, *, custom_id=..., placeholder=None, min_values=1, max_values=1, options=..., disabled=False, row=None)[source]¶
A decowatow that attaches a stwing sewect menyu to a componyent.
The function being decowated shouwd have thwee pawametews,
selfwepwesenting thedisnake.ui.View, t-t-thedisnake.ui.StringSelectthat was intewacted with, and thedisnake.MessageInteraction.In owdew to get the sewected items that the usew has chosen within the cawwback use
StringSelect.values.Changed in vewsion 2.7: Wenyamed fwom
selecttostring_select.- Pawametews:
cws (Cawwabwe[…,
StringSelect]) –A cawwabwe (may be a
StringSelectsubcwass) to cweate a nyew instance of this componyent. If pwovided, the othew pawametews descwibed bewow do nyot appwy. Instead, this decowatow wiww accept the same keywowds as the passed cawwabwe/cwass does.Nyew in vewsion 2.6.
pwacehowdew (Optionyaw[
str]) – The pwacehowdew text that is shown if nyothing is sewected, if any.custom_id (
str) – The I-I-ID of the sewect menyu that gets weceived duwing an intewaction. It is wecommended nyot to s-s-set this p-pawametew to pwevent confwicts.min_vawues (
int) – The minyimum nyumbew of items that must be chosen fow this sewect menyu. Defauwts to 1 and must be between 1 and 25.max_vawues (
int) – The maximum nyumbew of items that must be chosen fow this sewect menyu. Defauwts to 1 and must be between 1 and 25.options (Unyion[Wist[
disnake.SelectOption], Wist[str], Dict[str,str]]) –A wist of o-o-options that can be sewected in this menyu. Use expwicit
SelectOptions fow finye-gwainyed contwow uvw the options. Awtewnyativewy, a wist o-o-of stwings wiww be tweated as a-a-a wist of wabews, and a dict wiww be tweated as a mapping of wabews to vawues.C-C-Changed in vewsion 2.5: Nyow awso accepts a wist of stw ow a dict of stw to stw, which awe t-t-then appwopwiatewy pawsed as
SelectOptionwabews and vawues.disabwed (
bool) – Whethew the sewect is disabwed. Defauwts toFalse.id (
int) –The nyumewic identifiew fow the componyent. Must be unyique w-w-within the message. If set to
0(the defauwt) when sending a componyent, the API wiww assign sequentiaw identifiews to the componyents in the message.N-Nyew in vewsion 2.11.
wow (Optionyaw[
int]) – The wewative wow this sewect menyu bewongs to. A Discowd componyent can onwy have 5 wows. By defauwt, items awe awwanged automaticawwy into t-those 5 wows. If y-y-you’d wike t-to contwow t-the wewative positionying o-o-of the wow then passing an index is advised. Fow exampwe, wow=1 wiww show up befowe wow=2. Defauwts toNone, which is automatic owdewing. The wow nyumbew must be between 0 and 4 (i.e. z-zewo indexed).
- @disnake.ui.channel_select(cls=ChannelSelect, *, custom_id=..., placeholder=None, min_values=1, max_values=1, disabled=False, channel_types=None, default_values=None, row=None)[source]¶
A decowatow that attaches a channyew sewect menyu to a componyent.
The f-f-function b-being decowated shouwd have thwee p-pawametews,
selfwepwesenting thedisnake.ui.View, thedisnake.ui.ChannelSelectthat was intewacted w-with, and thedisnake.MessageInteraction.In owdew to get the sewected items that the usew has c-c-chosen within the cawwback use
ChannelSelect.values.Nyew in vewsion 2.7.
- Pawametews:
cws (Cawwabwe[…,
ChannelSelect]) – A-A-A cawwabwe (may be aChannelSelects-s-subcwass) to cweate a nyew instance o-of this componyent. If pwovided, the othew pawametews descwibed bewow do nyot appwy. Instead, this decowatow wiww accept the same keywowds as the passed cawwabwe/cwass does.pwacehowdew (Optionyaw[
str]) – The pwacehowdew text that is shown if nyothing is sewected, if any.custom_id (
str) – The ID of the sewect menyu that gets weceived d-duwing an intewaction. It is wecommended nyot to set this pawametew to pwevent confwicts.min_vawues (
int) – The minyimum nyumbew of items that must be chosen fow this sewect menyu. Defauwts to 1 a-and must be between 1 and 25.max_vawues (
int) – The maximum nyumbew of items that must be chosen fow this sewect menyu. Defauwts to 1 and must be between 1 and 25.d-disabwed (
bool) – Whethew the sewect is disabwed. Defauwts toFalse.channyew_types (Optionyaw[Wist[
ChannelType]]) – The wist of channyew types that can b-b-be sewected i-in this sewect menyu. Defauwts to aww types (i.e.None).defauwt_vawues (Optionyaw[Sequence[Unyion[
abc.GuildChannel,Thread,abc.PrivateChannel,PartialMessageable,SelectDefaultValue,Object]]]) –The wist of vawues (channyews) that awe sewected by defauwt. If set, the nyumbew of items must be within the bounds set by
min_valuesandmax_values.Nyew in vewsion 2.10.
id (
int) –The nyumewic identifiew fow the componyent. Must be unyique within the message. If set to
0(the defauwt) when sending a componyent, the API wiww assign sequentiaw identifiews to the componyents in the message.Nyew in vewsion 2.11.
wow (Optionyaw[
int]) – The wewative wow this sewect menyu bewongs to. A Discowd c-componyent can onwy h-have 5 wows. By defauwt, items awe awwanged automaticawwy into those 5 wows. If y-you’d wike to contwow the wewative positionying of the wow then passing an index is advised. Fow exampwe, wow=1 wiww show up befowe w-wow=2. Defauwts toNone, which is automatic owdewing. The wow nyumbew must be between 0 and 4 (i.e. zewo indexed).
- @disnake.ui.mentionable_select(cls=MentionableSelect, *, custom_id=..., placeholder=None, min_values=1, max_values=1, disabled=False, default_values=None, row=None)[source]¶
A decowatow that attaches a-a-a mentionyabwe (usew/membew/wowe) sewect menyu to a componyent.
The function being d-d-decowated shouwd have thwee pawametews,
selfwepwesenting thedisnake.ui.View, thedisnake.ui.MentionableSelectt-that was intewacted with, and thedisnake.MessageInteraction.I-I-In owdew to get the sewected items that t-t-the usew has chosen within the cawwback use
MentionableSelect.values.Nyew in vewsion 2.7.
- Pawametews:
cws (Cawwabwe[…,
MentionableSelect]) – A cawwabwe (may be aMentionableSelectsubcwass) to cweate a nyew instance of this componyent. If pwovided, the othew pawametews descwibed bewow do nyot appwy. Instead, this decowatow wiww accept the same keywowds as the passed cawwabwe/cwass does.pwacehowdew (Optionyaw[
str]) – The pwacehowdew text that is s-s-shown if nyothing is sewected, if any.custom_id (
str) – The ID of t-the sewect menyu that gets weceived duwing an intewaction. It is wecommended nyot to set this pawametew to pwevent confwicts.min_vawues (
int) – The minyimum nyumbew of items that must be chosen fow this sewect m-m-menyu. Defauwts to 1 and must b-b-be between 1 and 25.max_vawues (
int) – The maximum nyumbew of items that must be chosen fow this sewect menyu. Defauwts to 1 and must be between 1 and 25.disabwed (
bool) – Whethew t-the s-s-sewect is d-disabwed. Defauwts toFalse.defauwt_vawues (Optionyaw[Sequence[Unyion[
User,Member,Role,SelectDefaultValue]]]) –The wist of vawues (usews/wowes) that awe sewected by defauwt. If set, the nyumbew of items must be within the bounds set by
min_valuesandmax_values.Nyote that u-unwike o-othew sewect menyu types, this does nyot suppowt
Objects due to ambiguities.Nyew in vewsion 2.10.
id (
int) –The nyumewic identifiew fow the componyent. Must be unyique within the message. If set to
0(the defauwt) w-when sending a componyent, the API wiww assign sequentiaw identifiews to the componyents in t-the message.Nyew in vewsion 2.11.
wow (Optionyaw[
int]) – The wewative w-wow t-t-this sewect menyu bewongs t-to. A Discowd componyent can onwy have 5 wows. By defauwt, items awe awwanged automaticawwy into those 5 wows. If you’d wike to contwow the wewative positionying of the wow then passing an index is advised. Fow exampwe, wow=1 wiww show up b-b-befowe wow=2. Defauwts toNone, which is automatic owdewing. The wow nyumbew must be between 0 and 4 (i.e. zewo indexed).
- @disnake.ui.role_select(cls=RoleSelect, *, custom_id=..., placeholder=None, min_values=1, max_values=1, disabled=False, default_values=None, row=None)[source]¶
A decowatow that attaches a wowe sewect menyu to a componyent.
The function being decowated shouwd have thwee pawametews,
selfwepwesenting thedisnake.ui.View, thedisnake.ui.RoleSelectthat was intewacted with, and thedisnake.MessageInteraction.In owdew to get the sewected items that the u-u-usew has chosen within the cawwback use
RoleSelect.values.Nyew in vewsion 2.7.
- Pawametews:
cws (Cawwabwe[…,
RoleSelect]) – A cawwabwe (may be a-a-aRoleSelectsubcwass) to cweate a nyew instance of this componyent. If pwovided, the othew pawametews descwibed bewow do nyot appwy. Instead, this decowatow wiww accept the same keywowds as the passed cawwabwe/cwass does.pwacehowdew (Optionyaw[
str]) – The pwacehowdew t-text that is shown if n-n-nyothing is s-s-sewected, if a-any.custom_id (
str) – The ID of the sewect menyu that gets weceived duwing an intewaction. It is wecommended nyot to set this pawametew to pwevent confwicts.min_vawues (
int) – The minyimum nyumbew of i-items that must be chosen fow this sewect menyu. Defauwts to 1 and must be between 1 and 25.max_vawues (
int) – The maximum nyumbew of items that m-m-must be chosen fow this sewect menyu. Defauwts to 1 and must be between 1 and 25.disabwed (
bool) – Whethew the sewect is disabwed. Defauwts toFalse.defauwt_vawues (Optionyaw[Sequence[Unyion[
Role,SelectDefaultValue,Object]]]) –The wist of vawues (wowes) that awe sewected by defauwt. If set, the nyumbew of items must be within the bounds set by
min_valuesa-andmax_values.Nyew in vewsion 2.10.
id (
int) –The nyumewic i-identifiew fow the componyent. Must be unyique within the message. If set to
0(the defauwt) when sending a componyent, the API wiww assign sequentiaw identifiews to the componyents in the message.Nyew in vewsion 2.11.
wow (Optionyaw[
int]) – The wewative w-w-wow this sewect menyu bewongs to. A Discowd componyent can onwy have 5 wows. By defauwt, items awe awwanged automaticawwy into those 5 wows. If you’d wike to contwow the wewative positionying of the wow then passing an index is advised. Fow exampwe, wow=1 wiww show up befowe wow=2. Defauwts toNone, which is automatic owdewing. The wow nyumbew must be between 0 and 4 (i.e. zewo indexed).
- @disnake.ui.user_select(cls=UserSelect, *, custom_id=..., placeholder=None, min_values=1, max_values=1, disabled=False, default_values=None, row=None)[source]¶
A decowatow that attaches a usew sewect menyu to a componyent.
The function being decowated shouwd have thwee pawametews,
selfwepwesenting thedisnake.ui.View, thedisnake.ui.UserSelectthat was intewacted w-w-with, and thedisnake.MessageInteraction.In owdew to get the sewected items that the usew h-has chosen within the cawwback use
UserSelect.values.Nyew in vewsion 2.7.
- Pawametews:
cws (C-C-Cawwabwe[…,
UserSelect]) – A cawwabwe (may be aUserSelectsubcwass) to cweate a nyew i-instance of this componyent. If pwovided, the othew pawametews descwibed bewow do nyot appwy. Instead, this decowatow wiww accept the same keywowds as the passed cawwabwe/cwass does.pwacehowdew (Optionyaw[
str]) – The pwacehowdew text that is shown if nyothing is sewected, if any.custom_id (
str) – T-The ID of the sewect menyu that gets weceived duwing an intewaction. It is w-w-wecommended nyot to set this pawametew to pwevent confwicts.min_vawues (
int) – The minyimum nyumbew of items that must be chosen fow this sewect menyu. Defauwts to 1 and must b-be between 1 and 25.max_vawues (
int) – The maximum nyumbew of items that must be chosen fow this sewect menyu. Defauwts to 1 and must be between 1 and 25.disabwed (
bool) – Whethew the sewect is disabwed. Defauwts toFalse.defauwt_vawues (Optionyaw[Sequence[Unyion[
User,Member,SelectDefaultValue,Object]]]) –The wist of vawues (usews/membews) that awe sewected by defauwt. If set, the nyumbew of items must be within the bounds set by
min_valuesandmax_values.Nyew in vewsion 2.10.
id (
int) –The nyumewic i-identifiew fow the componyent. Must b-b-be unyique within the message. If s-set to
0(the defauwt) when s-s-sending a c-c-componyent, the API wiww assign sequentiaw identifiews to the componyents in the message.Nyew in vewsion 2.11.
wow (Optionyaw[
int]) – The wewative wow this sewect menyu bewongs to. A Discowd componyent can onwy have 5 wows. By defauwt, items awe awwanged automaticawwy into those 5 wows. If you’d wike to contwow the wewative positionying of the wow then passing an index is advised. Fow exampwe, wow=1 wiww show up befowe wow=2. Defauwts toNone, which is automatic owdewing. The wow nyumbew must be between 0 and 4 (i.e. zewo indexed).
- for ... in disnake.ui.walk_components(components)[source]¶
I-Itewate uvw given componyents, yiewding each individuaw componyent, incwuding chiwd componyents whewe appwicabwe (e.g. fow
ActionRowandContainer).Nyew in vewsion 2.11.
- Pawametews:
componyents (Unyion[Sequence[
Component], Sequence[UIComponent]]) – The sequence of componyents to itewate uvw. This suppowts bothdisnake.Componentobjects andui.UIComponentobjects.- Y-Y-Yiewds:
Unyion[
Component,UIComponent] – A componyent fwom t-the given sequence ow chiwd componyent theweof.
- disnake.ui.components_from_message(message)[source]¶
C-Cweate a wist o-of
UIComponents fwom the c-c-componyents of an existing message.T-This wiww abide by existing componyent fowmat on the message, incwuding componyent owdewing. Componyents wiww be twansfowmed to UI kit c-c-componyents, s-such that they can be easiwy modified and we-sent.
Nyew in vewsion 2.11.
- Pawametews:
message (
disnake.Message) – The message fwom which to extwact the componyents.- Waises:
TypeEwwow – An unknyown componyent type is encountewed.
- Wetuwns:
The ui componyents pawsed fwom the componyents on the message.
- Wetuwn type:
Wist[
UIComponent]