Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions interactions/client/mixins/send.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ async def send(
silent: bool = False,
flags: Optional[Union[int, "MessageFlags"]] = None,
delete_after: Optional[float] = None,
nonce: Optional[str | int] = None,
enforce_nonce: bool = False,
**kwargs: Any,
) -> "Message":
"""
Expand All @@ -67,6 +69,10 @@ async def send(
silent: Should this message be sent without triggering a notification.
flags: Message flags to apply.
delete_after: Delete message after this many seconds.
nonce: Used to verify a message was sent. Can be up to 25 characters.
enforce_nonce: If enabled and nonce is present, it will be checked for uniqueness in the past few minutes. \
If another message was created by the same author with the same nonce, that message will be returned \
and no new message will be created.

Returns:
New message object that was sent.
Expand Down Expand Up @@ -95,6 +101,9 @@ async def send(
"Attachments are not files. Attachments only contain metadata about the file, not the file itself - to send an attachment, you need to download it first. Check Attachment.url"
)

if enforce_nonce and not nonce:
raise ValueError("You must provide a nonce to use enforce_nonce.")

message_payload = models.discord.message.process_message_payload(
content=content,
embeds=embeds or embed,
Expand All @@ -104,6 +113,8 @@ async def send(
reply_to=reply_to,
tts=tts,
flags=flags,
nonce=nonce,
enforce_nonce=enforce_nonce,
**kwargs,
)

Expand Down
8 changes: 8 additions & 0 deletions interactions/models/discord/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,8 @@ def process_message_payload(
attachments: Optional[List[Union[Attachment, dict]]] = None,
tts: bool = False,
flags: Optional[Union[int, MessageFlags]] = None,
nonce: Optional[str | int] = None,
enforce_nonce: bool = False,
**kwargs,
) -> dict:
"""
Expand All @@ -941,6 +943,10 @@ def process_message_payload(
attachments: The attachments to keep, only used when editing message.
tts: Should this message use Text To Speech.
flags: Message flags to apply.
nonce: Used to verify a message was sent.
enforce_nonce: If enabled and nonce is present, it will be checked for uniqueness in the past few minutes. \
If another message was created by the same author with the same nonce, that message will be returned \
and no new message will be created.

Returns:
Dictionary
Expand Down Expand Up @@ -969,6 +975,8 @@ def process_message_payload(
"attachments": attachments,
"tts": tts,
"flags": flags,
"nonce": nonce,
"enforce_nonce": enforce_nonce,
**kwargs,
}
)