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:
Rapptz 2021-06-12 02:33:11 -04:00
parent f0c76a13d3
commit 1c640ad72b

View File

@ -267,11 +267,9 @@ def button(
"""
def decorator(func: ItemCallbackType) -> ItemCallbackType:
nonlocal custom_id
if not inspect.iscoroutinefunction(func):
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_kwargs__ = {
'style': style,