aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyber <[email protected]>2019-05-22 01:09:31 +1000
committerRapptz <[email protected]>2019-05-23 23:21:39 -0400
commitf2c7b2e6d81b000a64de8030be09157b7b06e92d (patch)
treeaf611f8767a16972c1961695f6747680127bf692
parentFix wording in documentation for ClientUser.locale (diff)
downloaddiscord.py-f2c7b2e6d81b000a64de8030be09157b7b06e92d.tar.xz
discord.py-f2c7b2e6d81b000a64de8030be09157b7b06e92d.zip
Add an insert_field_at method for the embed class
-rw-r--r--discord/embeds.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/discord/embeds.py b/discord/embeds.py
index b9ae584e..f4a0aac7 100644
--- a/discord/embeds.py
+++ b/discord/embeds.py
@@ -422,6 +422,39 @@ class Embed:
self._fields = [field]
return self
+
+ def insert_field_at(self, index, *, name, value, inline=True):
+ """Inserts a field before a specified index to the embed.
+
+ This function returns the class instance to allow for fluent-style
+ chaining.
+
+ .. versionadded:: 1.2.0
+
+ Parameters
+ -----------
+ index: :class:`int`
+ The index of where to insert the field.
+ name: :class:`str`
+ The name of the field.
+ value: :class:`str`
+ The value of the field.
+ inline: :class:`bool`
+ Whether the field should be displayed inline.
+ """
+
+ field = {
+ 'inline': inline,
+ 'name': str(name),
+ 'value': str(value)
+ }
+
+ try:
+ self._fields.insert(index, field)
+ except AttributeError:
+ self._fields = [field]
+
+ return self
def clear_fields(self):
"""Removes all fields from this embed."""