Skip to content

feat(http): add enforce_nonce to CreateMessage - #2570

Open
thomas-quant wants to merge 1 commit into
twilight-rs:mainfrom
thomas-quant:feat/enforce-nonce
Open

feat(http): add enforce_nonce to CreateMessage#2570
thomas-quant wants to merge 1 commit into
twilight-rs:mainfrom
thomas-quant:feat/enforce-nonce

Conversation

@thomas-quant

@thomas-quant thomas-quant commented Aug 10, 2026

Copy link
Copy Markdown

Adds enforce_nonce to CreateMessage, mirroring the existing tts builder.

nonce is already supported, but alone it is only echoed back. enforce_nonce is what makes a repeated create idempotent: without it, a transient failure arriving after Discord accepted a message is indistinguishable from one arriving before, and the retry posts a duplicate.

From Create Message → JSON/Form Params:

enforce_nonce? — If true 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.

Verified against the live API on a bot token, including on the multipart attachment path: two creates sharing a nonce return one message and one attachments[0].id, while the same pair without the flag returns two.

Discord's create-message endpoint accepts an `enforce_nonce` boolean alongside
`nonce`. When set, the nonce is checked for uniqueness against the author's
recent messages and an existing match is returned instead of a second message
being created.

`nonce` is already supported here, but on its own it is only echoed back — the
deduplication that makes a retried create idempotent requires `enforce_nonce`.
Without it, a transient failure arriving after Discord accepted a message is
indistinguishable from one arriving before, and the retry posts a duplicate.

Mirrors the existing `tts` builder.
@github-actions github-actions Bot added c-http Affects the http crate t-feature Addition of a new feature labels Aug 10, 2026
@raventhyme raventhyme added d-api Change related to Discord's API. w-do-not-merge PR is blocked or deferred labels Aug 10, 2026
@raventhyme

Copy link
Copy Markdown
Member

Hi,

Thank you for the pull request. The implementation looks good to me.

Thank you also for the since-deleted LLM implementation disclaimer. This project does not currently have a defined policy on when, if at all, to accept LLM generated contributions. I've raised this pull request with the team. It may be placed on hold until such a policy is drafted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c-http Affects the http crate d-api Change related to Discord's API. t-feature Addition of a new feature w-do-not-merge PR is blocked or deferred

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants