From 53dbcd600f54bdc3b1e497dc34e356e5abbca1a0 Mon Sep 17 00:00:00 2001 From: Conatum Date: Mon, 9 May 2022 21:08:23 +0300 Subject: [PATCH] (interactions): Add menu `set_default`. --- bot/meta/interactions/components.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/bot/meta/interactions/components.py b/bot/meta/interactions/components.py index ad2bdef9..efc0b6c6 100644 --- a/bot/meta/interactions/components.py +++ b/bot/meta/interactions/components.py @@ -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,