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