aboutsummaryrefslogtreecommitdiff
path: root/discord/abc.py
diff options
context:
space:
mode:
authorRapptz <[email protected]>2021-04-25 04:57:29 -0400
committerRapptz <[email protected]>2021-05-27 00:53:13 -0400
commit98570793e4af8dcfca25621e86fecd85297b0d59 (patch)
treeefcbe97935fa61126c642f00fdd3ebbc15b61375 /discord/abc.py
parentFix bug in Embed.__len__ caused by footer without text (diff)
downloaddiscord.py-98570793e4af8dcfca25621e86fecd85297b0d59.tar.xz
discord.py-98570793e4af8dcfca25621e86fecd85297b0d59.zip
Add initial support for buttons and components
Diffstat (limited to 'discord/abc.py')
-rw-r--r--discord/abc.py23
1 files changed, 19 insertions, 4 deletions
diff --git a/discord/abc.py b/discord/abc.py
index a16afe8e..961545ed 100644
--- a/discord/abc.py
+++ b/discord/abc.py
@@ -1154,7 +1154,7 @@ class Messageable(Protocol):
async def send(self, content=None, *, tts=False, embed=None, file=None,
files=None, delete_after=None, nonce=None,
allowed_mentions=None, reference=None,
- mention_author=None):
+ mention_author=None, view=None):
"""|coro|
Sends a message to the destination with the content given.
@@ -1212,6 +1212,10 @@ class Messageable(Protocol):
If set, overrides the :attr:`~discord.AllowedMentions.replied_user` attribute of ``allowed_mentions``.
.. versionadded:: 1.6
+ view: :class:`discord.ui.View`
+ A Discord UI View to add to the message.
+
+ .. versionadded:: 2.0
Raises
--------
@@ -1255,6 +1259,14 @@ class Messageable(Protocol):
except AttributeError:
raise InvalidArgument('reference parameter must be Message or MessageReference') from None
+ if view:
+ if not hasattr(view, '__discord_ui_view__'):
+ raise InvalidArgument(f'view parameter must be View not {view.__class__!r}')
+
+ components = view.to_components()
+ else:
+ components = None
+
if file is not None and files is not None:
raise InvalidArgument('cannot pass both file and files parameter to send()')
@@ -1265,7 +1277,7 @@ class Messageable(Protocol):
try:
data = await state.http.send_files(channel.id, files=[file], allowed_mentions=allowed_mentions,
content=content, tts=tts, embed=embed, nonce=nonce,
- message_reference=reference)
+ message_reference=reference, components=components)
finally:
file.close()
@@ -1278,16 +1290,19 @@ class Messageable(Protocol):
try:
data = await state.http.send_files(channel.id, files=files, content=content, tts=tts,
embed=embed, nonce=nonce, allowed_mentions=allowed_mentions,
- message_reference=reference)
+ message_reference=reference, components=components)
finally:
for f in files:
f.close()
else:
data = await state.http.send_message(channel.id, content, tts=tts, embed=embed,
nonce=nonce, allowed_mentions=allowed_mentions,
- message_reference=reference)
+ message_reference=reference, components=components)
ret = state.create_message(channel=channel, data=data)
+ if view:
+ state.store_view(view, ret.id)
+
if delete_after is not None:
await ret.delete(delay=delete_after)
return ret