Lazily create Button custom_ids in decorator interface
The previous code would make two separate instances share the custom_id which might have been undesirable behaviour
This commit is contained in:
parent
f0c76a13d3
commit
1c640ad72b
@ -267,11 +267,9 @@ def button(
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def decorator(func: ItemCallbackType) -> ItemCallbackType:
|
def decorator(func: ItemCallbackType) -> ItemCallbackType:
|
||||||
nonlocal custom_id
|
|
||||||
if not inspect.iscoroutinefunction(func):
|
if not inspect.iscoroutinefunction(func):
|
||||||
raise TypeError('button function must be a coroutine function')
|
raise TypeError('button function must be a coroutine function')
|
||||||
|
|
||||||
custom_id = custom_id or os.urandom(32).hex()
|
|
||||||
func.__discord_ui_model_type__ = Button
|
func.__discord_ui_model_type__ = Button
|
||||||
func.__discord_ui_model_kwargs__ = {
|
func.__discord_ui_model_kwargs__ = {
|
||||||
'style': style,
|
'style': style,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user