6666 from ..message import Attachment
6767 from ..abc import Snowflake
6868 from ..state import ConnectionState
69+ from ..ui import View
6970 from ..types .webhook import (
7071 Webhook as WebhookPayload ,
7172 )
@@ -290,8 +291,9 @@ def execute_webhook(
290291 files : Optional [Sequence [File ]] = None ,
291292 thread_id : Optional [int ] = None ,
292293 wait : bool = False ,
294+ with_components : bool = False ,
293295 ) -> MessagePayload :
294- params = {'wait' : int (wait )}
296+ params = {'wait' : int (wait ), 'with_components' : int ( with_components ) }
295297 if thread_id :
296298 params ['thread_id' ] = thread_id
297299 route = Route ('POST' , '/webhooks/{webhook_id}/{webhook_token}' , webhook_id = webhook_id , webhook_token = token )
@@ -919,6 +921,7 @@ def send(
919921 silent : bool = False ,
920922 applied_tags : List [ForumTag ] = MISSING ,
921923 poll : Poll = MISSING ,
924+ view : View = MISSING ,
922925 ) -> Optional [SyncWebhookMessage ]:
923926 """Sends a message using the webhook.
924927
@@ -991,6 +994,13 @@ def send(
991994 When sending a Poll via webhook, you cannot manually end it.
992995
993996 .. versionadded:: 2.4
997+ view: :class:`~discord.ui.View`
998+ The view to send with the message. This can only have URL buttons, which donnot
999+ require a state to be attached to it.
1000+
1001+ If you want to send a view with any component attached to it, check :meth:`Webhook.send`.
1002+
1003+ .. versionadded:: 2.5
9941004
9951005 Raises
9961006 --------
@@ -1004,8 +1014,9 @@ def send(
10041014 You specified both ``embed`` and ``embeds`` or ``file`` and ``files``
10051015 or ``thread`` and ``thread_name``.
10061016 ValueError
1007- The length of ``embeds`` was invalid or
1008- there was no token associated with this webhook.
1017+ The length of ``embeds`` was invalid, there was no token
1018+ associated with this webhook or you tried to send a view
1019+ with components other than URL buttons.
10091020
10101021 Returns
10111022 ---------
@@ -1027,6 +1038,13 @@ def send(
10271038 else :
10281039 flags = MISSING
10291040
1041+ if view is not MISSING :
1042+ if not hasattr (view , '__discord_ui_view__' ):
1043+ raise TypeError (f'expected view parameter to be of type View not { view .__class__ .__name__ } ' )
1044+
1045+ if view .is_dispatchable ():
1046+ raise ValueError ('SyncWebhook views can only contain URL buttons' )
1047+
10301048 if thread_name is not MISSING and thread is not MISSING :
10311049 raise TypeError ('Cannot mix thread_name and thread keyword arguments.' )
10321050
@@ -1050,6 +1068,7 @@ def send(
10501068 flags = flags ,
10511069 applied_tags = applied_tag_ids ,
10521070 poll = poll ,
1071+ view = view ,
10531072 ) as params :
10541073 adapter : WebhookAdapter = _get_webhook_adapter ()
10551074 thread_id : Optional [int ] = None
@@ -1065,6 +1084,7 @@ def send(
10651084 files = params .files ,
10661085 thread_id = thread_id ,
10671086 wait = wait ,
1087+ with_components = view is not MISSING ,
10681088 )
10691089
10701090 msg = None
0 commit comments