discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.29k stars 3.96k forks source link

Automated Message nonce handling #10323

Closed DEVTomatoCake closed 1 month ago

DEVTomatoCake commented 3 months ago

Which application or package is this feature request for?

discord.js

Feature

Discord recently added support for enforcing the nonce parameter when creating a Message, to be able to prevent duplicate messages in a short amount of time.

When using this, currently developers have to specify both a random nonce and enforceNonce: true either in every <BaseChannel>.send() function in the payload, or extend the class(es) themselves to handle it everywhere.

Ideal solution or implementation

A client option, disabled by default, to automatically generate a nonce (e.g. using SnowflakeUtil.generate().toString()) and set both nonce and (while it's still required) enforceNonce when creating a Message, unless one or both of those parameters are already present in the payload.

Alternative solutions or implementations

A Message payload parameter like sendNonce which does the same as above, but it's per Message instead of globally.

Other context

See #10301 for why this could be useful.

rifqifuadi commented 3 months ago

same