From a0b0a97e5256721e8b994ecafc6a721a8a7f80d0 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Sun, 27 Oct 2024 14:49:41 -0400 Subject: [PATCH] Support enforce_nonce and add random nonce for message creation --- discord/abc.py | 4 ++++ discord/http.py | 1 + 2 files changed, 5 insertions(+) diff --git a/discord/abc.py b/discord/abc.py index af2b15dac..891404b33 100644 --- a/discord/abc.py +++ b/discord/abc.py @@ -26,6 +26,7 @@ from __future__ import annotations import copy import time +import secrets import asyncio from datetime import datetime from typing import ( @@ -1614,6 +1615,9 @@ class Messageable: else: flags = MISSING + if nonce is None: + nonce = secrets.randbits(64) + with handle_message_parameters( content=content, tts=tts, diff --git a/discord/http.py b/discord/http.py index fbaf447aa..c66132055 100644 --- a/discord/http.py +++ b/discord/http.py @@ -197,6 +197,7 @@ def handle_message_parameters( if nonce is not None: payload['nonce'] = str(nonce) + payload['enforce_nonce'] = True if message_reference is not MISSING: payload['message_reference'] = message_reference