(interactions): Add menu set_default.

This commit is contained in:
2022-05-09 21:08:23 +03:00
parent ad5ef537c9
commit 53dbcd600f

View File

@@ -134,6 +134,22 @@ class SelectMenu(MessageComponent, AwaitableComponent):
self.max_values = max_values
self.disabled = disabled
def set_default(self, value=None, index=None):
"""
Convenience method to set the default option.
"""
if index is not None and value is not None:
raise ValueError("Both index and value were supplied for the default.")
if index is not None:
for i, option in enumerate(self.options):
option.default = (i == index)
elif value is not None:
for option in self.options:
option.default = (option.value == value)
else:
for option in self.options:
option.default = False
def to_dict(self):
data = {
"type": self._type,