Return embed from clear_fields and remove_field

This commit is contained in:
Jonah Lawrence 2022-05-04 21:53:50 -06:00 committed by GitHub
parent 7b65be9d25
commit 1451074d66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -602,24 +602,39 @@ class Embed:
return self return self
def clear_fields(self) -> None: def clear_fields(self) -> Self:
"""Removes all fields from this embed.""" """Removes all fields from this embed.
This function returns the class instance to allow for fluent-style
chaining.
.. versionchanged:: 2.0
This function now returns the class instance.
"""
try: try:
self._fields.clear() self._fields.clear()
except AttributeError: except AttributeError:
self._fields = [] self._fields = []
def remove_field(self, index: int) -> None: return self
def remove_field(self, index: int) -> Self:
"""Removes a field at a specified index. """Removes a field at a specified index.
If the index is invalid or out of bounds then the error is If the index is invalid or out of bounds then the error is
silently swallowed. silently swallowed.
This function returns the class instance to allow for fluent-style
chaining.
.. note:: .. note::
When deleting a field by index, the index of the other fields When deleting a field by index, the index of the other fields
shift to fill the gap just like a regular list. shift to fill the gap just like a regular list.
.. versionchanged:: 2.0
This function now returns the class instance.
Parameters Parameters
----------- -----------
index: :class:`int` index: :class:`int`
@ -630,6 +645,8 @@ class Embed:
except (AttributeError, IndexError): except (AttributeError, IndexError):
pass pass
return self
def set_field_at(self, index: int, *, name: Any, value: Any, inline: bool = True) -> Self: def set_field_at(self, index: int, *, name: Any, value: Any, inline: bool = True) -> Self:
"""Modifies a field to the embed object. """Modifies a field to the embed object.