Default Settings Types¶
GigaJoyce provides several ready-to-use Setting
implementations under settings.DefaultTypes
.
Each type is documented directly from its source docstring, and below you’ll find practical examples of how to compose them into real modules.
settings.DefaultTypes.arr
¶
ArraySetting
¶
Bases: Setting[List[Any]]
A composite setting that manages an array of values interactively.
This setting renders an embed with Add, Remove, and Confirm UI,
delegates item creation/edition to a child Setting
, and optionally exposes
additional “general” settings as extra buttons.
Notes
- The visual content can be customized via
embed_override
orupdate_fn
. - If
locales=True
andmodule_name
is set, text goes through the module translator for i18n.
Source code in settings/DefaultTypes/arr.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
|
__init__(name, description, id, child, value=None, general_settings=None, embed_override=None, update_fn=None, locales=False, module_name=None)
¶
Initialize an ArraySetting
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Human‑readable name. |
required |
description
|
str
|
Short explanation for help/UX. |
required |
id
|
str
|
Unique persistence key. |
required |
child
|
Setting[Any]
|
Setting used to create/edit each array item. |
required |
value
|
Optional[List[Any]]
|
Initial list value. |
None
|
general_settings
|
Optional[List[Setting[Any]]]
|
Optional settings exposed as extra buttons. |
None
|
embed_override
|
Optional[Embed]
|
Static embed to render instead of the default. |
None
|
update_fn
|
Optional[Callable[[List[T]], Embed]]
|
Callable that builds a custom embed from current values. |
None
|
locales
|
Optional[bool]
|
Enable i18n of display strings. |
False
|
module_name
|
Optional[str]
|
Module name for translation/emoji lookups. |
None
|
Source code in settings/DefaultTypes/arr.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|
apply_locale(translate_module, clone=False)
¶
Apply module‑scoped translation to all display fields.
If self.locales
is truthy, this will translate name
, description
,
and any string values inside kwargs
using the provided function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
translate_module
|
Callable[[str], str]
|
Function that maps a translation key to its value. |
required |
clone
|
Optional[bool]
|
If True, returns a new translated copy of this setting;
otherwise returns a tuple |
False
|
Returns:
Type | Description |
---|---|
Union[Setting[T], tuple[str, str, str]]
|
|
Union[Setting[T], tuple[str, str, str]]
|
|
Union[Setting[T], tuple[str, str, str]]
|
|
Source code in settings/Setting.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
|
parse(config, client, guild_data, guild)
async
¶
Parses the configuration data from the database or input.
Source code in settings/DefaultTypes/arr.py
308 309 310 311 312 313 314 315 316 317 |
|
parse_from_database(config)
¶
Reconstructs the array values from the database.
Source code in settings/DefaultTypes/arr.py
300 301 302 303 304 305 306 |
|
parse_to_database(value)
¶
Converts the array values into a format suitable for database storage.
Source code in settings/DefaultTypes/arr.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
|
parse_to_field(value, translator=None)
¶
Converts a single array value into a displayable string format.
Source code in settings/DefaultTypes/arr.py
258 259 260 261 262 263 264 265 266 267 268 269 270 |
|
parse_to_field_list(translate_module=None)
¶
Converts the array values into fields for the embed.
Source code in settings/DefaultTypes/arr.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
|
propagate_locales(child)
¶
Propagate locales
and module_name
flags to a child setting.
Useful when composite settings are composed of other settings and you want consistent translation behavior across the hierarchy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
child
|
Setting[Any]
|
The setting that should inherit locale info. |
required |
Source code in settings/Setting.py
217 218 219 220 221 222 223 224 225 226 227 228 |
|
run(view)
async
¶
Run the interactive UI to modify the array.
Flow
- Render the embed (using
update_fn
or default renderer). - Add → delegates to
self.child.run(...)
and appends result. - Remove → shows a Select to remove an item by index.
- General buttons → delegates to each provided setting.
- Confirm → persists current state and ends the view.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
view
|
InteractionView
|
Active |
required |
Returns:
Type | Description |
---|---|
List[T]
|
The final list of values. |
Source code in settings/DefaultTypes/arr.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
|
save(client, entity, setting)
async
¶
Persist the setting value using the client DB API.
Default behavior
- Serializes
setting.value
viaparse_to_database
if available. - Writes to:
guilds
collection with filter{"_id": str(guild.id)}
whenentity
is aGuild
;members
collection with filter{"_id": str(member.id)}
whenentity
is aMember
.
Note
If your schema uses different keys (e.g., composite keys
{"id": ..., "guildId": ...}
for members), override this method in
your concrete setting type or adapt it at call‑site.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client
|
ExtendedClient
|
Extended bot client (exposes |
required |
entity
|
Union[Guild, Member]
|
Guild or Member instance that owns the setting. |
required |
setting
|
Setting[T]
|
The concrete |
required |
Returns:
Type | Description |
---|---|
bool
|
An awaitable that resolves truthy on success. |
Source code in settings/Setting.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
Example¶
tags_setting = ArraySetting(
name="Allowed tags",
description="List of allowed tags for message filtering",
id="allowed_tags",
child=StringSettingFile(
name="Tag",
description="One tag entry",
id="tag_entry"
)
)
settings.DefaultTypes.boolean
¶
BooleanSetting
¶
Bases: Setting[bool]
Represents a boolean setting that can be modified via interactions.
Source code in settings/DefaultTypes/boolean.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
__init__(name, description, id, value=None, color='#ffffff', locales=False, module_name=None)
¶
Initialize a BooleanSetting
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Display name. |
required |
description
|
str
|
Short explanation. |
required |
id
|
str
|
Persistence key. |
required |
value
|
Optional[bool]
|
Initial value (defaults to |
None
|
color
|
str
|
Hex color to render the embed. |
'#ffffff'
|
locales
|
Optional[bool]
|
Enable i18n of display strings. |
False
|
module_name
|
Optional[str]
|
Module context for translations. |
None
|
Source code in settings/DefaultTypes/boolean.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
apply_locale(translate_module, clone=False)
¶
Apply module‑scoped translation to all display fields.
If self.locales
is truthy, this will translate name
, description
,
and any string values inside kwargs
using the provided function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
translate_module
|
Callable[[str], str]
|
Function that maps a translation key to its value. |
required |
clone
|
Optional[bool]
|
If True, returns a new translated copy of this setting;
otherwise returns a tuple |
False
|
Returns:
Type | Description |
---|---|
Union[Setting[T], tuple[str, str, str]]
|
|
Union[Setting[T], tuple[str, str, str]]
|
|
Union[Setting[T], tuple[str, str, str]]
|
|
Source code in settings/Setting.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
|
clone()
¶
Return a shallow copy of this setting instance.
The copy is constructed by re‑invoking the concrete class __init__
with parameters that exist as attributes on self
.
Returns:
Type | Description |
---|---|
Setting[T]
|
A new instance of the concrete |
Source code in settings/Setting.py
230 231 232 233 234 235 236 237 238 239 240 241 242 |
|
parse(config, client, guild_data, guild)
async
¶
Optional async hook to parse a value with context.
Subclasses may override this to perform context‑aware parsing (e.g.
resolve IDs to Discord objects). Default behavior returns config
as‑is.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Any
|
Raw config value from DB or input. |
required |
client
|
ExtendedClient
|
Extended bot client. |
required |
guild_data
|
Any
|
Raw guild document (for extra context if needed). |
required |
guild
|
Guild
|
Hydrated guild wrapper. |
required |
Returns:
Type | Description |
---|---|
Awaitable[T]
|
The parsed value (usually of type |
Source code in settings/Setting.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
parse_from_database(config)
¶
Reconstruct the runtime value from the DB representation.
This is the inverse of parse_to_database
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Any
|
Raw stored value from the database. |
required |
Returns:
Type | Description |
---|---|
T
|
The deserialized runtime value of type |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If the subclass does not override this method. |
Source code in settings/Setting.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
parse_to_database(value)
¶
Prepares the channel for storage in the database.
Source code in settings/DefaultTypes/boolean.py
94 95 96 97 98 |
|
propagate_locales(child)
¶
Propagate locales
and module_name
flags to a child setting.
Useful when composite settings are composed of other settings and you want consistent translation behavior across the hierarchy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
child
|
Setting[Any]
|
The setting that should inherit locale info. |
required |
Source code in settings/Setting.py
217 218 219 220 221 222 223 224 225 226 227 228 |
|
run(view)
async
¶
Render two buttons to toggle the boolean value.
Returns the final value when the view ends (or current value on timeout).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
view
|
InteractionView
|
Active |
required |
Source code in settings/DefaultTypes/boolean.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
|
save(client, entity, setting)
async
¶
Persist the setting value using the client DB API.
Default behavior
- Serializes
setting.value
viaparse_to_database
if available. - Writes to:
guilds
collection with filter{"_id": str(guild.id)}
whenentity
is aGuild
;members
collection with filter{"_id": str(member.id)}
whenentity
is aMember
.
Note
If your schema uses different keys (e.g., composite keys
{"id": ..., "guildId": ...}
for members), override this method in
your concrete setting type or adapt it at call‑site.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client
|
ExtendedClient
|
Extended bot client (exposes |
required |
entity
|
Union[Guild, Member]
|
Guild or Member instance that owns the setting. |
required |
setting
|
Setting[T]
|
The concrete |
required |
Returns:
Type | Description |
---|---|
bool
|
An awaitable that resolves truthy on success. |
Source code in settings/Setting.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
Example¶
remove_previous_role = BooleanSetting(
name="Remove previous role",
description="Whether the bot should remove old roles when assigning new ones",
id="remove_previous_role",
value=False,
)
settings.DefaultTypes.channel
¶
ChannelSetting
¶
Bases: Setting[GuildChannel]
Represents a setting for selecting a Discord channel.
Source code in settings/DefaultTypes/channel.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
|
apply_locale(translate_module, clone=False)
¶
Apply module‑scoped translation to all display fields.
If self.locales
is truthy, this will translate name
, description
,
and any string values inside kwargs
using the provided function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
translate_module
|
Callable[[str], str]
|
Function that maps a translation key to its value. |
required |
clone
|
Optional[bool]
|
If True, returns a new translated copy of this setting;
otherwise returns a tuple |
False
|
Returns:
Type | Description |
---|---|
Union[Setting[T], tuple[str, str, str]]
|
|
Union[Setting[T], tuple[str, str, str]]
|
|
Union[Setting[T], tuple[str, str, str]]
|
|
Source code in settings/Setting.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
|
clone()
¶
Return a shallow copy of this setting instance.
The copy is constructed by re‑invoking the concrete class __init__
with parameters that exist as attributes on self
.
Returns:
Type | Description |
---|---|
Setting[T]
|
A new instance of the concrete |
Source code in settings/Setting.py
230 231 232 233 234 235 236 237 238 239 240 241 242 |
|
parse(config, guild)
async
¶
Parses a channel ID into a GuildChannel object.
Source code in settings/DefaultTypes/channel.py
148 149 150 151 152 153 154 155 |
|
parse_from_database(config)
¶
Reconstruct the runtime value from the DB representation.
This is the inverse of parse_to_database
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Any
|
Raw stored value from the database. |
required |
Returns:
Type | Description |
---|---|
T
|
The deserialized runtime value of type |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If the subclass does not override this method. |
Source code in settings/Setting.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
parse_to_database(value)
¶
Prepares the channel for storage in the database.
Source code in settings/DefaultTypes/channel.py
142 143 144 145 146 |
|
parse_to_field(value)
¶
Converts the value to a display-friendly string.
Source code in settings/DefaultTypes/channel.py
157 158 159 160 161 |
|
propagate_locales(child)
¶
Propagate locales
and module_name
flags to a child setting.
Useful when composite settings are composed of other settings and you want consistent translation behavior across the hierarchy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
child
|
Setting[Any]
|
The setting that should inherit locale info. |
required |
Source code in settings/Setting.py
217 218 219 220 221 222 223 224 225 226 227 228 |
|
run(view)
async
¶
Initialize a ChannelSetting
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
Display name. |
required | |
description
|
Description text. |
required | |
id
|
Persistence key. |
required | |
channel_types
|
Allowed channel classes (default: |
required | |
value
|
Preselected channel. |
required | |
max_values
|
Max selections in the Select. |
required | |
min_values
|
Min selections in the Select. |
required | |
color
|
Hex embed color. |
required | |
locales
|
Enable i18n of display strings. |
required | |
module_name
|
Module context for translations. |
required |
Source code in settings/DefaultTypes/channel.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
|
save(client, entity, setting)
async
¶
Persist the setting value using the client DB API.
Default behavior
- Serializes
setting.value
viaparse_to_database
if available. - Writes to:
guilds
collection with filter{"_id": str(guild.id)}
whenentity
is aGuild
;members
collection with filter{"_id": str(member.id)}
whenentity
is aMember
.
Note
If your schema uses different keys (e.g., composite keys
{"id": ..., "guildId": ...}
for members), override this method in
your concrete setting type or adapt it at call‑site.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client
|
ExtendedClient
|
Extended bot client (exposes |
required |
entity
|
Union[Guild, Member]
|
Guild or Member instance that owns the setting. |
required |
setting
|
Setting[T]
|
The concrete |
required |
Returns:
Type | Description |
---|---|
bool
|
An awaitable that resolves truthy on success. |
Source code in settings/Setting.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
Example¶
log_channel = ChannelSetting(
name="Log channel",
description="Channel where logs will be sent",
id="log_channel"
)
settings.DefaultTypes.dynamicSelect
¶
DynamicSelectSetting
¶
Bases: Setting[List[str]]
Split a list into rows of size
.
Source code in settings/DefaultTypes/dynamicSelect.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
|
__init__(name, description, id, get_fn, max_values=1, min_values=1, style='StringSelectMenu', value=None, permission=None)
¶
Initialize a DynamicSelectSetting
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Display name. |
required |
description
|
str
|
Description text. |
required |
id
|
str
|
Persistence key. |
required |
get_fn
|
Callable[[Member], List[str]]
|
Callable that returns option labels for the current member. |
required |
max_values
|
Optional[int]
|
Maximum options selectable. |
1
|
min_values
|
Optional[int]
|
Minimum options selectable. |
1
|
style
|
Optional[str]
|
"StringSelectMenu" or "Button". |
'StringSelectMenu'
|
value
|
Optional[List[str]]
|
Initial selection. |
None
|
permission
|
Optional[int]
|
Optional permission flag/bit. |
None
|
Source code in settings/DefaultTypes/dynamicSelect.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
apply_locale(translate_module, clone=False)
¶
Apply module‑scoped translation to all display fields.
If self.locales
is truthy, this will translate name
, description
,
and any string values inside kwargs
using the provided function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
translate_module
|
Callable[[str], str]
|
Function that maps a translation key to its value. |
required |
clone
|
Optional[bool]
|
If True, returns a new translated copy of this setting;
otherwise returns a tuple |
False
|
Returns:
Type | Description |
---|---|
Union[Setting[T], tuple[str, str, str]]
|
|
Union[Setting[T], tuple[str, str, str]]
|
|
Union[Setting[T], tuple[str, str, str]]
|
|
Source code in settings/Setting.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
|
parse(config, client, guild_data, guild)
async
¶
Optional async hook to parse a value with context.
Subclasses may override this to perform context‑aware parsing (e.g.
resolve IDs to Discord objects). Default behavior returns config
as‑is.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Any
|
Raw config value from DB or input. |
required |
client
|
ExtendedClient
|
Extended bot client. |
required |
guild_data
|
Any
|
Raw guild document (for extra context if needed). |
required |
guild
|
Guild
|
Hydrated guild wrapper. |
required |
Returns:
Type | Description |
---|---|
Awaitable[T]
|
The parsed value (usually of type |
Source code in settings/Setting.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
parse_from_database(config)
¶
Reconstruct the runtime value from the DB representation.
This is the inverse of parse_to_database
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Any
|
Raw stored value from the database. |
required |
Returns:
Type | Description |
---|---|
T
|
The deserialized runtime value of type |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If the subclass does not override this method. |
Source code in settings/Setting.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
parse_to_database(value)
¶
Serialize the runtime value into a DB‑friendly representation.
This is the inverse of parse_from_database
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
T
|
The runtime value. |
required |
Returns:
Type | Description |
---|---|
Any
|
A JSON‑serializable value suitable for your database. |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If the subclass does not override this method. |
Source code in settings/Setting.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
|
propagate_locales(child)
¶
Propagate locales
and module_name
flags to a child setting.
Useful when composite settings are composed of other settings and you want consistent translation behavior across the hierarchy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
child
|
Setting[Any]
|
The setting that should inherit locale info. |
required |
Source code in settings/Setting.py
217 218 219 220 221 222 223 224 225 226 227 228 |
|
save(client, entity, setting)
async
¶
Persist the setting value using the client DB API.
Default behavior
- Serializes
setting.value
viaparse_to_database
if available. - Writes to:
guilds
collection with filter{"_id": str(guild.id)}
whenentity
is aGuild
;members
collection with filter{"_id": str(member.id)}
whenentity
is aMember
.
Note
If your schema uses different keys (e.g., composite keys
{"id": ..., "guildId": ...}
for members), override this method in
your concrete setting type or adapt it at call‑site.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client
|
ExtendedClient
|
Extended bot client (exposes |
required |
entity
|
Union[Guild, Member]
|
Guild or Member instance that owns the setting. |
required |
setting
|
Setting[T]
|
The concrete |
required |
Returns:
Type | Description |
---|---|
bool
|
An awaitable that resolves truthy on success. |
Source code in settings/Setting.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
chunk_array(arr, size)
¶
Split a list into rows of size
.
Source code in settings/DefaultTypes/dynamicSelect.py
15 16 17 |
|
Example¶
category_setting = DynamicSelectSetting(
name="Category selector",
description="Pick a category from a dynamic list",
id="category_selector",
options_fn=lambda: ["News", "Updates", "Events"]
)
settings.DefaultTypes.embed
¶
EmbedSettingFile
¶
Bases: Setting[Embed]
Interactive setting for building a Discord Embed
with a wizard.
Source code in settings/DefaultTypes/embed.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
|
__init__(name, description, id, module_name=None, locales=False, value=None)
¶
Initialize an EmbedSettingFile
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Display name. |
required |
description
|
str
|
UX text. |
required |
id
|
str
|
Persistence key. |
required |
module_name
|
str
|
Module context for translations. |
None
|
locales
|
Optional[bool]
|
Enable i18n of display strings. |
False
|
value
|
Embed
|
Initial embed (used to prefill the editor). |
None
|
Source code in settings/DefaultTypes/embed.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
apply_locale(translate_module, clone=False)
¶
Apply module‑scoped translation to all display fields.
If self.locales
is truthy, this will translate name
, description
,
and any string values inside kwargs
using the provided function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
translate_module
|
Callable[[str], str]
|
Function that maps a translation key to its value. |
required |
clone
|
Optional[bool]
|
If True, returns a new translated copy of this setting;
otherwise returns a tuple |
False
|
Returns:
Type | Description |
---|---|
Union[Setting[T], tuple[str, str, str]]
|
|
Union[Setting[T], tuple[str, str, str]]
|
|
Union[Setting[T], tuple[str, str, str]]
|
|
Source code in settings/Setting.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
|
clone()
¶
Clones the current embed setting.
Returns:
Name | Type | Description |
---|---|---|
EmbedSettingFile |
EmbedSettingFile
|
A clone of this setting. |
Source code in settings/DefaultTypes/embed.py
102 103 104 105 106 107 108 109 110 111 |
|
parse(config)
¶
Parses a stored configuration back into an Embed object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
dict
|
The configuration dictionary. |
required |
Returns:
Name | Type | Description |
---|---|---|
Embed |
Embed
|
The parsed Embed object. |
Source code in settings/DefaultTypes/embed.py
74 75 76 77 78 79 80 81 82 83 84 |
|
parse_from_database(config)
¶
Reconstruct the runtime value from the DB representation.
This is the inverse of parse_to_database
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Any
|
Raw stored value from the database. |
required |
Returns:
Type | Description |
---|---|
T
|
The deserialized runtime value of type |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If the subclass does not override this method. |
Source code in settings/Setting.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
parse_to_database(value)
¶
Converts the embed to a database-storable format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
Embed
|
The embed to be parsed. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
The parsed embed in dictionary format. |
Source code in settings/DefaultTypes/embed.py
62 63 64 65 66 67 68 69 70 71 72 |
|
parse_to_field(value, translate)
¶
Converts the embed to a concise string representation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
Embed
|
The embed to be represented. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
A concise description of the embed. |
Source code in settings/DefaultTypes/embed.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
|
propagate_locales(child)
¶
Propagate locales
and module_name
flags to a child setting.
Useful when composite settings are composed of other settings and you want consistent translation behavior across the hierarchy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
child
|
Setting[Any]
|
The setting that should inherit locale info. |
required |
Source code in settings/Setting.py
217 218 219 220 221 222 223 224 225 226 227 228 |
|
run(view)
async
¶
Open the interactive embed creator and return the result.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
view
|
InteractionView
|
Active |
required |
Returns:
Type | Description |
---|---|
Embed
|
The resulting |
Raises:
Type | Description |
---|---|
ValueError
|
If creation is aborted or fails. |
Source code in settings/DefaultTypes/embed.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
|
save(client, entity, setting)
async
¶
Persist the setting value using the client DB API.
Default behavior
- Serializes
setting.value
viaparse_to_database
if available. - Writes to:
guilds
collection with filter{"_id": str(guild.id)}
whenentity
is aGuild
;members
collection with filter{"_id": str(member.id)}
whenentity
is aMember
.
Note
If your schema uses different keys (e.g., composite keys
{"id": ..., "guildId": ...}
for members), override this method in
your concrete setting type or adapt it at call‑site.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client
|
ExtendedClient
|
Extended bot client (exposes |
required |
entity
|
Union[Guild, Member]
|
Guild or Member instance that owns the setting. |
required |
setting
|
Setting[T]
|
The concrete |
required |
Returns:
Type | Description |
---|---|
bool
|
An awaitable that resolves truthy on success. |
Source code in settings/Setting.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
Example¶
welcome_embed = EmbedSetting(
name="Welcome embed",
description="Embed shown to new members",
id="welcome_embed"
)
settings.DefaultTypes.member
¶
MemberSetting
¶
Bases: Setting[GuildMember]
Interactive setting to pick a guild member.
Source code in settings/DefaultTypes/member.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
|
__init__(name, description, id, max_select=1, min_select=1, placeholder=None, embed_description=None, color='#ffffff', value=None, locales=False, module_name=None)
¶
Initialize a MemberSetting
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Display name. |
required |
description
|
str
|
Description text. |
required |
id
|
str
|
Persistence key. |
required |
max_select
|
Optional[int]
|
Max users selectable. |
1
|
min_select
|
Optional[int]
|
Min users selectable. |
1
|
placeholder
|
Optional[str]
|
Custom placeholder text. |
None
|
embed_description
|
Optional[str]
|
Override for the embed description. |
None
|
color
|
Optional[str]
|
Hex embed color. |
'#ffffff'
|
value
|
Optional[GuildMember]
|
Preselected member. |
None
|
locales
|
Optional[bool]
|
Enable i18n of display strings. |
False
|
module_name
|
Optional[str]
|
Module context for translations. |
None
|
Source code in settings/DefaultTypes/member.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
|
apply_locale(translate_module, clone=False)
¶
Apply module‑scoped translation to all display fields.
If self.locales
is truthy, this will translate name
, description
,
and any string values inside kwargs
using the provided function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
translate_module
|
Callable[[str], str]
|
Function that maps a translation key to its value. |
required |
clone
|
Optional[bool]
|
If True, returns a new translated copy of this setting;
otherwise returns a tuple |
False
|
Returns:
Type | Description |
---|---|
Union[Setting[T], tuple[str, str, str]]
|
|
Union[Setting[T], tuple[str, str, str]]
|
|
Union[Setting[T], tuple[str, str, str]]
|
|
Source code in settings/Setting.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
|
clone()
¶
Clones the current setting instance.
Source code in settings/DefaultTypes/member.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
|
parse(config, client, data, guild)
async
¶
Parses a member ID from the configuration and fetches the member.
Source code in settings/DefaultTypes/member.py
114 115 116 117 118 119 120 121 |
|
parse_from_database(config)
¶
Reconstruct the runtime value from the DB representation.
This is the inverse of parse_to_database
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Any
|
Raw stored value from the database. |
required |
Returns:
Type | Description |
---|---|
T
|
The deserialized runtime value of type |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If the subclass does not override this method. |
Source code in settings/Setting.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
parse_to_database(value)
¶
Parses the member to its database representation.
Source code in settings/DefaultTypes/member.py
123 124 125 126 127 |
|
parse_to_field(value)
¶
Parses the member to a displayable field.
Source code in settings/DefaultTypes/member.py
129 130 131 132 133 |
|
propagate_locales(child)
¶
Propagate locales
and module_name
flags to a child setting.
Useful when composite settings are composed of other settings and you want consistent translation behavior across the hierarchy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
child
|
Setting[Any]
|
The setting that should inherit locale info. |
required |
Source code in settings/Setting.py
217 218 219 220 221 222 223 224 225 226 227 228 |
|
run(view)
async
¶
Runs the interactive session for selecting a guild member.
Source code in settings/DefaultTypes/member.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
|
save(client, entity, setting)
async
¶
Persist the setting value using the client DB API.
Default behavior
- Serializes
setting.value
viaparse_to_database
if available. - Writes to:
guilds
collection with filter{"_id": str(guild.id)}
whenentity
is aGuild
;members
collection with filter{"_id": str(member.id)}
whenentity
is aMember
.
Note
If your schema uses different keys (e.g., composite keys
{"id": ..., "guildId": ...}
for members), override this method in
your concrete setting type or adapt it at call‑site.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client
|
ExtendedClient
|
Extended bot client (exposes |
required |
entity
|
Union[Guild, Member]
|
Guild or Member instance that owns the setting. |
required |
setting
|
Setting[T]
|
The concrete |
required |
Returns:
Type | Description |
---|---|
bool
|
An awaitable that resolves truthy on success. |
Source code in settings/Setting.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
Example¶
admin_member = MemberSetting(
name="Admin user",
description="The user with administrator privileges",
id="admin_user"
)
settings.DefaultTypes.number
¶
NumberSetting
¶
Bases: Setting[int]
Interactive numeric setting.
Allows the user to input a single integer value through an interactive flow, validating bounds and showing a preview of the new value before saving.
Source code in settings/DefaultTypes/number.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
|
__init__(name, description, id, value=None, minValue=None, maxValue=None, color='#ffffff', locales=False, module_name=None)
¶
Initialize a NumberSetting.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Display name. |
required |
description
|
str
|
UX description. |
required |
id
|
str
|
Persistence key. |
required |
value
|
Optional[int]
|
Initial value. |
None
|
minValue
|
Optional[int]
|
Minimum allowed value (inclusive). |
None
|
maxValue
|
Optional[int]
|
Maximum allowed value (inclusive). |
None
|
color
|
Optional[str]
|
Hex color for the embed. |
'#ffffff'
|
locales
|
Optional[bool]
|
Enable i18n of display strings. |
False
|
module_name
|
Optional[str]
|
Module context for translations. |
None
|
Source code in settings/DefaultTypes/number.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
apply_locale(translate_module, clone=False)
¶
Apply module‑scoped translation to all display fields.
If self.locales
is truthy, this will translate name
, description
,
and any string values inside kwargs
using the provided function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
translate_module
|
Callable[[str], str]
|
Function that maps a translation key to its value. |
required |
clone
|
Optional[bool]
|
If True, returns a new translated copy of this setting;
otherwise returns a tuple |
False
|
Returns:
Type | Description |
---|---|
Union[Setting[T], tuple[str, str, str]]
|
|
Union[Setting[T], tuple[str, str, str]]
|
|
Union[Setting[T], tuple[str, str, str]]
|
|
Source code in settings/Setting.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
|
clone()
¶
Return a shallow clone preserving bounds and i18n context.
Source code in settings/DefaultTypes/number.py
178 179 180 181 182 183 184 185 186 187 188 189 190 |
|
parse(config, client, guild_data, guild)
async
¶
Optional async hook to parse a value with context.
Subclasses may override this to perform context‑aware parsing (e.g.
resolve IDs to Discord objects). Default behavior returns config
as‑is.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Any
|
Raw config value from DB or input. |
required |
client
|
ExtendedClient
|
Extended bot client. |
required |
guild_data
|
Any
|
Raw guild document (for extra context if needed). |
required |
guild
|
Guild
|
Hydrated guild wrapper. |
required |
Returns:
Type | Description |
---|---|
Awaitable[T]
|
The parsed value (usually of type |
Source code in settings/Setting.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
parse_from_database(config)
¶
Parse the numerical value from database format.
Source code in settings/DefaultTypes/number.py
165 166 167 168 169 |
|
parse_to_database(value)
¶
Parse the numerical value for database storage.
Source code in settings/DefaultTypes/number.py
159 160 161 162 163 |
|
parse_to_field(value, translator=None)
¶
Parse the value to a displayable string format.
Source code in settings/DefaultTypes/number.py
171 172 173 174 175 176 |
|
propagate_locales(child)
¶
Propagate locales
and module_name
flags to a child setting.
Useful when composite settings are composed of other settings and you want consistent translation behavior across the hierarchy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
child
|
Setting[Any]
|
The setting that should inherit locale info. |
required |
Source code in settings/Setting.py
217 218 219 220 221 222 223 224 225 226 227 228 |
|
run(view)
async
¶
Runs the interactive session for configuring the numerical setting.
Source code in settings/DefaultTypes/number.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
|
save(client, entity, setting)
async
¶
Persist the setting value using the client DB API.
Default behavior
- Serializes
setting.value
viaparse_to_database
if available. - Writes to:
guilds
collection with filter{"_id": str(guild.id)}
whenentity
is aGuild
;members
collection with filter{"_id": str(member.id)}
whenentity
is aMember
.
Note
If your schema uses different keys (e.g., composite keys
{"id": ..., "guildId": ...}
for members), override this method in
your concrete setting type or adapt it at call‑site.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client
|
ExtendedClient
|
Extended bot client (exposes |
required |
entity
|
Union[Guild, Member]
|
Guild or Member instance that owns the setting. |
required |
setting
|
Setting[T]
|
The concrete |
required |
Returns:
Type | Description |
---|---|
bool
|
An awaitable that resolves truthy on success. |
Source code in settings/Setting.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
Example¶
multiplier = NumberSetting(
name="XP Multiplier",
description="Multiplier applied to all XP gains",
id="xp_multiplier",
value=1,
minValue=0.1,
maxValue=10,
)
settings.DefaultTypes.option
¶
OptionSetting
¶
Bases: Setting[T]
, Generic[T]
Single-choice setting built from a list of child Setting
s.
Each option is represented by a child Setting
used only for metadata
(name/id/value). The user selects one option via buttons.
Source code in settings/DefaultTypes/option.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
|
__init__(name, description, id, options, value=None, permission=None, locales=False, module_name=None)
¶
Initialize an OptionSetting.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Display name. |
required |
description
|
str
|
UX description. |
required |
id
|
str
|
Persistence key. |
required |
options
|
List[Setting[T]]
|
List of child settings representing choices. |
required |
value
|
Optional[T]
|
Initial selected value. |
None
|
permission
|
Optional[T]
|
Optional permission flag/bit. |
None
|
locales
|
Optional[bool]
|
Enable i18n of display strings. |
False
|
module_name
|
Optional[str]
|
Module context for translations. |
None
|
Source code in settings/DefaultTypes/option.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
|
apply_locale(translate_module)
¶
Applies the modular translation to all fields, including options.
Source code in settings/DefaultTypes/option.py
64 65 66 67 68 69 70 71 72 |
|
clone()
¶
Return a clone of this selector (options are shallow‑cloned).
Notes
We clone each child option if it has clone()
, otherwise we reuse
the instance (safe for read‑only metadata).
Source code in settings/DefaultTypes/option.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
|
parse(config, client, guild_data, guild)
async
¶
Optional async hook to parse a value with context.
Subclasses may override this to perform context‑aware parsing (e.g.
resolve IDs to Discord objects). Default behavior returns config
as‑is.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Any
|
Raw config value from DB or input. |
required |
client
|
ExtendedClient
|
Extended bot client. |
required |
guild_data
|
Any
|
Raw guild document (for extra context if needed). |
required |
guild
|
Guild
|
Hydrated guild wrapper. |
required |
Returns:
Type | Description |
---|---|
Awaitable[T]
|
The parsed value (usually of type |
Source code in settings/Setting.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
parse_from_database(config)
¶
Parse the value from the database configuration.
Source code in settings/DefaultTypes/option.py
160 161 162 163 164 |
|
parse_to_database(value, translator=None)
¶
Parse the selected value for database storage.
Source code in settings/DefaultTypes/option.py
154 155 156 157 158 |
|
parse_to_field(value)
¶
Parse the value to a displayable string format.
Source code in settings/DefaultTypes/option.py
166 167 168 169 170 171 |
|
propagate_locales(child)
¶
Propagate locales
and module_name
flags to a child setting.
Useful when composite settings are composed of other settings and you want consistent translation behavior across the hierarchy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
child
|
Setting[Any]
|
The setting that should inherit locale info. |
required |
Source code in settings/Setting.py
217 218 219 220 221 222 223 224 225 226 227 228 |
|
run(view)
async
¶
Render the selector and return the chosen option's value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
view
|
InteractionView
|
Active interaction view. |
required |
Returns:
Type | Description |
---|---|
T
|
The selected option value. |
Raises:
Type | Description |
---|---|
TimeoutError
|
When the user does not choose in time. |
Source code in settings/DefaultTypes/option.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
|
save(client, entity, setting)
async
¶
Persist the setting value using the client DB API.
Default behavior
- Serializes
setting.value
viaparse_to_database
if available. - Writes to:
guilds
collection with filter{"_id": str(guild.id)}
whenentity
is aGuild
;members
collection with filter{"_id": str(member.id)}
whenentity
is aMember
.
Note
If your schema uses different keys (e.g., composite keys
{"id": ..., "guildId": ...}
for members), override this method in
your concrete setting type or adapt it at call‑site.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client
|
ExtendedClient
|
Extended bot client (exposes |
required |
entity
|
Union[Guild, Member]
|
Guild or Member instance that owns the setting. |
required |
setting
|
Setting[T]
|
The concrete |
required |
Returns:
Type | Description |
---|---|
bool
|
An awaitable that resolves truthy on success. |
Source code in settings/Setting.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
Example¶
theme_setting = OptionSetting(
name="Theme",
description="Choose a theme for your server",
id="theme",
options=["Dark", "Light", "Classic"],
value="Dark"
)
settings.DefaultTypes.role
¶
RoleSetting
¶
Bases: Setting[Role]
Interactive role selector.
Renders a dropdown with all non‑managed roles in the guild and persists the selected role.
Source code in settings/DefaultTypes/role.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
|
__init__(name, description, id, max_values=1, min_values=1, placeholder=None, embed_description=None, color='#ffffff', value=None, locales=False, module_name=None)
¶
Initialize a RoleSetting.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Display name. |
required |
description
|
str
|
UX description. |
required |
id
|
str
|
Persistence key. |
required |
max_values
|
Optional[int]
|
Max selectable roles. |
1
|
min_values
|
Optional[int]
|
Min selectable roles. |
1
|
placeholder
|
Optional[str]
|
Placeholder for the select. |
None
|
embed_description
|
Optional[str]
|
Optional description override. |
None
|
color
|
str
|
Hex color for the embed. |
'#ffffff'
|
value
|
Optional[Role]
|
Initial role. |
None
|
locales
|
Optional[bool]
|
Enable i18n of display strings. |
False
|
module_name
|
Optional[str]
|
Module context for translations. |
None
|
Source code in settings/DefaultTypes/role.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
|
apply_locale(translate_module, clone=False)
¶
Apply module‑scoped translation to all display fields.
If self.locales
is truthy, this will translate name
, description
,
and any string values inside kwargs
using the provided function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
translate_module
|
Callable[[str], str]
|
Function that maps a translation key to its value. |
required |
clone
|
Optional[bool]
|
If True, returns a new translated copy of this setting;
otherwise returns a tuple |
False
|
Returns:
Type | Description |
---|---|
Union[Setting[T], tuple[str, str, str]]
|
|
Union[Setting[T], tuple[str, str, str]]
|
|
Union[Setting[T], tuple[str, str, str]]
|
|
Source code in settings/Setting.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
|
clone()
¶
Return a shallow clone preserving selector configuration.
Source code in settings/DefaultTypes/role.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
|
parse(config, client, guild_data, guild)
async
¶
Parse the role from the database configuration.
Source code in settings/DefaultTypes/role.py
140 141 142 143 144 |
|
parse_from_database(config)
¶
Reconstruct the runtime value from the DB representation.
This is the inverse of parse_to_database
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Any
|
Raw stored value from the database. |
required |
Returns:
Type | Description |
---|---|
T
|
The deserialized runtime value of type |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If the subclass does not override this method. |
Source code in settings/Setting.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
parse_to_database(value)
¶
Parse the role to a database-friendly format.
Source code in settings/DefaultTypes/role.py
134 135 136 137 138 |
|
parse_to_field(value, translator=None)
¶
Parse the role to a displayable string format.
Source code in settings/DefaultTypes/role.py
146 147 148 149 150 151 152 153 |
|
propagate_locales(child)
¶
Propagate locales
and module_name
flags to a child setting.
Useful when composite settings are composed of other settings and you want consistent translation behavior across the hierarchy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
child
|
Setting[Any]
|
The setting that should inherit locale info. |
required |
Source code in settings/Setting.py
217 218 219 220 221 222 223 224 225 226 227 228 |
|
run(view)
async
¶
Render the dropdown and return the chosen role.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
view
|
InteractionView
|
Active interaction view. |
required |
Returns:
Type | Description |
---|---|
Role
|
The selected |
Raises:
Type | Description |
---|---|
TimeoutError
|
If the selection is not completed in time. |
Source code in settings/DefaultTypes/role.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
|
save(client, entity, setting)
async
¶
Persist the setting value using the client DB API.
Default behavior
- Serializes
setting.value
viaparse_to_database
if available. - Writes to:
guilds
collection with filter{"_id": str(guild.id)}
whenentity
is aGuild
;members
collection with filter{"_id": str(member.id)}
whenentity
is aMember
.
Note
If your schema uses different keys (e.g., composite keys
{"id": ..., "guildId": ...}
for members), override this method in
your concrete setting type or adapt it at call‑site.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client
|
ExtendedClient
|
Extended bot client (exposes |
required |
entity
|
Union[Guild, Member]
|
Guild or Member instance that owns the setting. |
required |
setting
|
Setting[T]
|
The concrete |
required |
Returns:
Type | Description |
---|---|
bool
|
An awaitable that resolves truthy on success. |
Source code in settings/Setting.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
Example¶
vip_role = RoleSetting(
name="VIP Role",
description="Role given to VIP members",
id="vip_role"
)
settings.DefaultTypes.select
¶
SelectSetting
¶
Bases: Setting[str]
Single-select setting based on a predefined list of (label, value) options.
Source code in settings/DefaultTypes/select.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
|
__init__(name, description, id, options, value=None, max_values=1, min_values=1, color='#ffffff', permission=None, locales=False, module_name=None)
¶
Initialize a SelectSetting.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Display name. |
required |
description
|
str
|
UX description. |
required |
id
|
str
|
Persistence key. |
required |
options
|
List[Dict[str, str]]
|
List of dicts with |
required |
value
|
Optional[str]
|
Initial selected value. |
None
|
max_values
|
Optional[int]
|
Max selectable (kept for API parity, UI uses single select). |
1
|
min_values
|
Optional[int]
|
Min selectable. |
1
|
color
|
str
|
Hex color for the embed. |
'#ffffff'
|
permission
|
Optional[int]
|
Optional permission flag/bit. |
None
|
locales
|
Optional[bool]
|
Enable i18n of display strings. |
False
|
module_name
|
Optional[str]
|
Module context for translations. |
None
|
Source code in settings/DefaultTypes/select.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
apply_locale(translate_module, clone=False)
¶
Apply module‑scoped translation to all display fields.
If self.locales
is truthy, this will translate name
, description
,
and any string values inside kwargs
using the provided function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
translate_module
|
Callable[[str], str]
|
Function that maps a translation key to its value. |
required |
clone
|
Optional[bool]
|
If True, returns a new translated copy of this setting;
otherwise returns a tuple |
False
|
Returns:
Type | Description |
---|---|
Union[Setting[T], tuple[str, str, str]]
|
|
Union[Setting[T], tuple[str, str, str]]
|
|
Union[Setting[T], tuple[str, str, str]]
|
|
Source code in settings/Setting.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
|
clone()
¶
Return a shallow clone preserving available options and i18n context.
Source code in settings/DefaultTypes/select.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
|
parse(config, client, guild_data, guild)
async
¶
Optional async hook to parse a value with context.
Subclasses may override this to perform context‑aware parsing (e.g.
resolve IDs to Discord objects). Default behavior returns config
as‑is.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Any
|
Raw config value from DB or input. |
required |
client
|
ExtendedClient
|
Extended bot client. |
required |
guild_data
|
Any
|
Raw guild document (for extra context if needed). |
required |
guild
|
Guild
|
Hydrated guild wrapper. |
required |
Returns:
Type | Description |
---|---|
Awaitable[T]
|
The parsed value (usually of type |
Source code in settings/Setting.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
parse_from_database(config)
¶
Parse the value from a database configuration.
Source code in settings/DefaultTypes/select.py
126 127 128 129 130 |
|
parse_to_database(value)
¶
Parse the value to a database-friendly format.
Source code in settings/DefaultTypes/select.py
118 119 120 121 122 123 124 |
|
parse_to_field(value)
¶
Parse the value to a displayable string format.
Source code in settings/DefaultTypes/select.py
132 133 134 135 136 137 |
|
propagate_locales(child)
¶
Propagate locales
and module_name
flags to a child setting.
Useful when composite settings are composed of other settings and you want consistent translation behavior across the hierarchy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
child
|
Setting[Any]
|
The setting that should inherit locale info. |
required |
Source code in settings/Setting.py
217 218 219 220 221 222 223 224 225 226 227 228 |
|
run(view)
async
¶
Render a dropdown list and return the selected string value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
view
|
InteractionView
|
Active interaction view. |
required |
Returns:
Type | Description |
---|---|
str
|
The selected option |
Raises:
Type | Description |
---|---|
TimeoutError
|
When selection does not complete in time. |
Source code in settings/DefaultTypes/select.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
|
save(client, entity, setting)
async
¶
Persist the setting value using the client DB API.
Default behavior
- Serializes
setting.value
viaparse_to_database
if available. - Writes to:
guilds
collection with filter{"_id": str(guild.id)}
whenentity
is aGuild
;members
collection with filter{"_id": str(member.id)}
whenentity
is aMember
.
Note
If your schema uses different keys (e.g., composite keys
{"id": ..., "guildId": ...}
for members), override this method in
your concrete setting type or adapt it at call‑site.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client
|
ExtendedClient
|
Extended bot client (exposes |
required |
entity
|
Union[Guild, Member]
|
Guild or Member instance that owns the setting. |
required |
setting
|
Setting[T]
|
The concrete |
required |
Returns:
Type | Description |
---|---|
bool
|
An awaitable that resolves truthy on success. |
Source code in settings/Setting.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
Example¶
region_select = SelectSetting(
name="Server Region",
description="Choose the server region",
id="server_region",
options=["US-East", "US-West", "Europe", "Asia"],
value="US-East"
)
settings.DefaultTypes.string
¶
StringSettingFile
¶
Bases: Setting[str]
Interactive free‑text string setting with optional validation.
Source code in settings/DefaultTypes/string.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
__init__(name, description, id, filter=None, color='#ffffff', value=None, locales=False, module_name=None)
¶
Initialize a StringSettingFile.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Display name. |
required |
description
|
str
|
UX description. |
required |
id
|
str
|
Persistence key. |
required |
filter
|
Optional[Dict[str, Any]]
|
Optional dict with keys: |
None
|
color
|
str
|
Hex color for the embed. |
'#ffffff'
|
value
|
Optional[str]
|
Initial value. |
None
|
locales
|
Optional[bool]
|
Enable i18n of display strings. |
False
|
module_name
|
Optional[str]
|
Module context for translations. |
None
|
Source code in settings/DefaultTypes/string.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
apply_locale(translate_module, clone=False)
¶
Apply module‑scoped translation to all display fields.
If self.locales
is truthy, this will translate name
, description
,
and any string values inside kwargs
using the provided function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
translate_module
|
Callable[[str], str]
|
Function that maps a translation key to its value. |
required |
clone
|
Optional[bool]
|
If True, returns a new translated copy of this setting;
otherwise returns a tuple |
False
|
Returns:
Type | Description |
---|---|
Union[Setting[T], tuple[str, str, str]]
|
|
Union[Setting[T], tuple[str, str, str]]
|
|
Union[Setting[T], tuple[str, str, str]]
|
|
Source code in settings/Setting.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
|
clone()
¶
Clone the current instance.
Source code in settings/DefaultTypes/string.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
parse(config, client, guild_data, guild)
async
¶
Optional async hook to parse a value with context.
Subclasses may override this to perform context‑aware parsing (e.g.
resolve IDs to Discord objects). Default behavior returns config
as‑is.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Any
|
Raw config value from DB or input. |
required |
client
|
ExtendedClient
|
Extended bot client. |
required |
guild_data
|
Any
|
Raw guild document (for extra context if needed). |
required |
guild
|
Guild
|
Hydrated guild wrapper. |
required |
Returns:
Type | Description |
---|---|
Awaitable[T]
|
The parsed value (usually of type |
Source code in settings/Setting.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
parse_from_database(config)
¶
Reconstruct the runtime value from the DB representation.
This is the inverse of parse_to_database
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Any
|
Raw stored value from the database. |
required |
Returns:
Type | Description |
---|---|
T
|
The deserialized runtime value of type |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If the subclass does not override this method. |
Source code in settings/Setting.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
parse_to_database(value)
¶
Parse the value to a database-friendly format.
Source code in settings/DefaultTypes/string.py
154 155 156 157 158 |
|
parse_to_field(value)
¶
Parse the value to a displayable string format.
Source code in settings/DefaultTypes/string.py
160 161 162 163 164 |
|
propagate_locales(child)
¶
Propagate locales
and module_name
flags to a child setting.
Useful when composite settings are composed of other settings and you want consistent translation behavior across the hierarchy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
child
|
Setting[Any]
|
The setting that should inherit locale info. |
required |
Source code in settings/Setting.py
217 218 219 220 221 222 223 224 225 226 227 228 |
|
run(view)
async
¶
Render the editor, collect free text, validate, and return it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
view
|
InteractionView
|
Active interaction view. |
required |
Returns:
Type | Description |
---|---|
str
|
The updated string value. |
Raises:
Type | Description |
---|---|
TimeoutError
|
When the user does not provide input in time. |
Source code in settings/DefaultTypes/string.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
|
save(client, entity, setting)
async
¶
Persist the setting value using the client DB API.
Default behavior
- Serializes
setting.value
viaparse_to_database
if available. - Writes to:
guilds
collection with filter{"_id": str(guild.id)}
whenentity
is aGuild
;members
collection with filter{"_id": str(member.id)}
whenentity
is aMember
.
Note
If your schema uses different keys (e.g., composite keys
{"id": ..., "guildId": ...}
for members), override this method in
your concrete setting type or adapt it at call‑site.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client
|
ExtendedClient
|
Extended bot client (exposes |
required |
entity
|
Union[Guild, Member]
|
Guild or Member instance that owns the setting. |
required |
setting
|
Setting[T]
|
The concrete |
required |
Returns:
Type | Description |
---|---|
bool
|
An awaitable that resolves truthy on success. |
Source code in settings/Setting.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
Example¶
bank_name_setting = StringSettingFile(
name="Bank name",
description="The display name of your guild bank",
id="bank_name",
value="GigaBank"
)
settings.DefaultTypes.complex
¶
ComplexSetting
¶
Bases: Setting[Dict[str, Any]]
A composite setting that edits a dict of child settings interactively.
Renders one button per child field; clicking a button opens the child setting UI. A Confirm button validates required fields and finalizes.
Attributes:
Name | Type | Description |
---|---|---|
schema |
Ordered map of field key -> child |
|
update_fn |
Callable (sync or async) that builds the current summary embed. |
|
optionals |
Optional list of keys that are not required. |
Source code in settings/DefaultTypes/complex.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
|
__init__(name, description, id, schema, update_fn, optionals=None, value=None, locales=False, module_name=None)
¶
Initialize a ComplexSetting
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Display name. |
required |
description
|
str
|
Description for UX. |
required |
id
|
str
|
Persistence key. |
required |
schema
|
Dict[str, Setting[Any]]
|
Child settings map (one button per key). |
required |
update_fn
|
Callable[[Dict[str, Any], InteractionView], Embed]
|
Function that summarizes current state into an embed. |
required |
optionals
|
Optional[List[str]]
|
Keys that may be omitted. |
None
|
value
|
Optional[Dict[str, Any]]
|
Initial value (defaults to |
None
|
locales
|
Optional[bool]
|
Enable i18n of display strings. |
False
|
module_name
|
Optional[str]
|
Module context for translations/emojis. |
None
|
Source code in settings/DefaultTypes/complex.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
|
apply_locale(translate_module, clone=False)
¶
Apply module‑scoped translation to all display fields.
If self.locales
is truthy, this will translate name
, description
,
and any string values inside kwargs
using the provided function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
translate_module
|
Callable[[str], str]
|
Function that maps a translation key to its value. |
required |
clone
|
Optional[bool]
|
If True, returns a new translated copy of this setting;
otherwise returns a tuple |
False
|
Returns:
Type | Description |
---|---|
Union[Setting[T], tuple[str, str, str]]
|
|
Union[Setting[T], tuple[str, str, str]]
|
|
Union[Setting[T], tuple[str, str, str]]
|
|
Source code in settings/Setting.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
|
parse(config, client, guild_data, guild)
async
¶
Parses the configuration data from the database or input.
Source code in settings/DefaultTypes/complex.py
266 267 268 269 270 271 272 273 274 275 276 277 278 |
|
parse_from_database(config)
¶
Reconstruct the runtime value from the DB representation.
This is the inverse of parse_to_database
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Any
|
Raw stored value from the database. |
required |
Returns:
Type | Description |
---|---|
T
|
The deserialized runtime value of type |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If the subclass does not override this method. |
Source code in settings/Setting.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
parse_to_database(value)
¶
Prepares the complex value for database storage.
Source code in settings/DefaultTypes/complex.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
|
propagate_locales(child)
¶
Propagate locales
and module_name
flags to a child setting.
Useful when composite settings are composed of other settings and you want consistent translation behavior across the hierarchy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
child
|
Setting[Any]
|
The setting that should inherit locale info. |
required |
Source code in settings/Setting.py
217 218 219 220 221 222 223 224 225 226 227 228 |
|
run(view)
async
¶
Render the complex editor and handle child edits/confirmation.
Flow
- Build a summary embed via
update_fn
. - Render a button for each
schema
key; clicking opens the child. - Confirm validates required fields via
check_filled_schema
. - On success, closes the view and returns the dict.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
view
|
InteractionView
|
Active |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Final dictionary value. |
Source code in settings/DefaultTypes/complex.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
|
save(client, entity, setting)
async
¶
Persist the setting value using the client DB API.
Default behavior
- Serializes
setting.value
viaparse_to_database
if available. - Writes to:
guilds
collection with filter{"_id": str(guild.id)}
whenentity
is aGuild
;members
collection with filter{"_id": str(member.id)}
whenentity
is aMember
.
Note
If your schema uses different keys (e.g., composite keys
{"id": ..., "guildId": ...}
for members), override this method in
your concrete setting type or adapt it at call‑site.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client
|
ExtendedClient
|
Extended bot client (exposes |
required |
entity
|
Union[Guild, Member]
|
Guild or Member instance that owns the setting. |
required |
setting
|
Setting[T]
|
The concrete |
required |
Returns:
Type | Description |
---|---|
bool
|
An awaitable that resolves truthy on success. |
Source code in settings/Setting.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
check_filled_schema(current_config)
¶
Check if all required schema fields are present in .value
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
current_config
|
ComplexSetting
|
The complex setting instance. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if all required fields are filled; otherwise False. |
Source code in settings/DefaultTypes/complex.py
42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
chunk_arr(arr, size)
¶
Split a list into chunks of size size
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arr
|
List[Any]
|
Input list. |
required |
size
|
int
|
Chunk size. |
required |
Returns:
Type | Description |
---|---|
List[List[Any]]
|
List of chunks. |
Source code in settings/DefaultTypes/complex.py
29 30 31 32 33 34 35 36 37 38 39 |
|
clone_schema(schema)
¶
Deep‑clone a schema by calling .clone()
on each child setting.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
schema
|
Dict[str, T]
|
Original mapping. |
required |
Returns:
Type | Description |
---|---|
Dict[str, T]
|
New ordered mapping with cloned children. |
Source code in settings/DefaultTypes/complex.py
57 58 59 60 61 62 63 64 65 66 |
|
map_schema(schema)
¶
Normalize a schema to an ordered dict for deterministic iteration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
schema
|
Dict[str, Setting[Any]]
|
Mapping of field key -> |
required |
Returns:
Type | Description |
---|---|
Dict[str, Setting[Any]]
|
Ordered mapping suitable for stable rendering / iteration. |
Source code in settings/DefaultTypes/complex.py
17 18 19 20 21 22 23 24 25 26 |
|
Example¶
xp_settings = ComplexSetting(
name="XP system",
description="Configure XP roles and multipliers",
id="xp_system",
schema={
"role": RoleSetting(
name="XP role",
description="Role assigned at a certain XP",
id="xp_role"
),
"xp_required": NumberSetting(
name="XP required",
description="XP required to unlock the role",
id="xp_required",
value=1000,
minValue=1,
maxValue=999999
),
"remove_previous_role": BooleanSetting(
name="Remove previous role",
description="Remove older XP roles when a new one is assigned",
id="remove_previous_role",
value=True
)
}
)
ComplexSetting allows you to compose multiple child settings together into a single structured object, making it the foundation for advanced configurations like the XP system or the economy module.