Browse Source

Change View child mutators to be fluent-style methods

pull/7723/head
Pat 3 years ago
committed by GitHub
parent
commit
94f4da9248
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      discord/ui/view.py

19
discord/ui/view.py

@ -252,9 +252,10 @@ class View:
view.add_item(_component_to_item(component)) view.add_item(_component_to_item(component))
return view return view
def add_item(self, item: Item[Any]) -> None: def add_item(self, item: Item[Any]) -> Self:
"""Adds an item to the view. """Adds an item to the view.
This function returns the class instance to allow for fluent-style
chaining.
Parameters Parameters
----------- -----------
item: :class:`Item` item: :class:`Item`
@ -279,9 +280,12 @@ class View:
item._view = self item._view = self
self.children.append(item) self.children.append(item)
return self
def remove_item(self, item: Item[Any]) -> None: def remove_item(self, item: Item[Any]) -> Self:
"""Removes an item from the view. """Removes an item from the view.
This function returns the class instance to allow for fluent-style
chaining.
Parameters Parameters
----------- -----------
@ -295,11 +299,16 @@ class View:
pass pass
else: else:
self.__weights.remove_item(item) self.__weights.remove_item(item)
return self
def clear_items(self) -> None: def clear_items(self) -> Self:
"""Removes all items from the view.""" """Removes all items from the view.
This function returns the class instance to allow for fluent-style
chaining.
"""
self.children.clear() self.children.clear()
self.__weights.clear() self.__weights.clear()
return self
async def interaction_check(self, interaction: Interaction) -> bool: async def interaction_check(self, interaction: Interaction) -> bool:
"""|coro| """|coro|

Loading…
Cancel
Save