Comments (2)
These logs are coming from Discord, so it's not a discord.js issue. You should open an issue over at https://github.com/discord/discord-api-docs and report your findings.
from discord.js.
Simple temporary solution for users
Warning: This assumes you only want to handle
MESSAGE_UPDATE
event when the author edits their messages (you can actually see theedited
label in their messages from Discord's UI). If you want to handle more complexMESSAGE_UPDATE
cases like component only update, embed suppression etc., please edit the if statement.
client.on(Events.MessageUpdate, (oldMsg, newMsg) => {
if (oldMsg.editedTimestamp === newMsg.editedTimestamp) return;
// ...
});
Reason for this to work
Take a look at the previous redundant MESSAGE_UPDATE
packets:
./debug.json
[
{
"t": "MESSAGE_UPDATE",
"s": 86,
"op": 0,
"d": {
"id": "1211645783686782996",
"channel_id": "748114061966835772",
"attachments": [],
"guild_id": "678164358378946580"
}
},
{
"t": "MESSAGE_UPDATE",
"s": 87,
"op": 0,
"d": {
"webhook_id": "826343609824575504",
"type": 20,
"tts": false,
"timestamp": "2024-02-26T12:07:46.121000+00:00",
"position": 0,
"pinned": false,
"mentions": [],
"mention_roles": [],
"mention_everyone": false,
"member": {
"roles": [
"710374276049534977",
"986909666820898867",
"678176821321138189",
"742414428208758815"
],
"premium_since": null,
"pending": false,
"nick": "( b. ) Bloony 🌸",
"mute": false,
"joined_at": "2022-09-16T20:35:00.838000+00:00",
"flags": 0,
"deaf": false,
"communication_disabled_until": null,
"avatar": null
},
"interaction_metadata": {
"user_id": "676103178323886085",
"type": 2,
"name": "ping",
"id": "1211645782789201970",
"authorizing_integration_owners": {
"0": "678164358378946580"
}
},
"interaction": {
"user": {
"username": "bloonatics",
"public_flags": 4194432,
"id": "676103178323886085",
"global_name": "Bloonatics",
"discriminator": "0",
"avatar_decoration_data": null,
"avatar": "a236da7641db588ca84c75541a8c8759"
},
"type": 2,
"name": "ping",
"member": {
"roles": [
"756248495110881360",
"995756877075988570",
"986909666820898867"
],
"premium_since": null,
"pending": false,
"nick": "Bloonatics 🌸",
"mute": false,
"joined_at": "2020-04-24T06:59:30.136000+00:00",
"flags": 2,
"deaf": false,
"communication_disabled_until": null,
"avatar": null
},
"id": "1211645782789201970"
},
"id": "1211645783686782996",
"flags": 0,
"embeds": [
{
"type": "rich",
"title": "Pong!",
"footer": {
"text": "bloonatics",
"proxy_icon_url": "https://images-ext-2.discordapp.net/external/xRotzEa3IhzPRr5ah464AOJarA5gfjVMDeDuFVvr4ng/https/cdn.discordapp.com/avatars/676103178323886085/a236da7641db588ca84c75541a8c8759.webp",
"icon_url": "https://cdn.discordapp.com/avatars/676103178323886085/a236da7641db588ca84c75541a8c8759.webp"
},
"description": "Roundtrip latency: `241ms`\nWebsocket heartbeat: `74ms`",
"color": 12845022
}
],
"edited_timestamp": "2024-02-26T12:07:46.412817+00:00",
"content": "",
"components": [],
"channel_id": "748114061966835772",
"author": {
"username": "Bloony",
"public_flags": 65536,
"premium_type": 0,
"id": "826343609824575504",
"global_name": null,
"discriminator": "0615",
"bot": true,
"avatar_decoration_data": null,
"avatar": "a_c7b487a96f23f21aac1a54125d821714"
},
"attachments": [],
"application_id": "826343609824575504",
"guild_id": "678164358378946580"
}
},
{
"t": "MESSAGE_UPDATE",
"s": 88,
"op": 0,
"d": {
"id": "1211645783686782996",
"channel_id": "748114061966835772",
"attachments": [],
"guild_id": "678164358378946580"
}
}
]
Focus on the first packet:
{
"t": "MESSAGE_UPDATE",
"s": 86,
"op": 0,
"d": {
"id": "1211645783686782996",
"channel_id": "748114061966835772",
"attachments": [],
"guild_id": "678164358378946580"
}
}
Please note that this data does not have edited_timestamp
and the complete structure of this message is cached because of the MESSAGE_CREATE
event just before it. In this case, the Message
structure of both oldMsg
and newMsg
are exactly the same (I know that attachments
would be updated, but both are empty array in this case) plus the Message#editedTimestamp
of them are both null
, i.e. this data is unnecessary. We can ignore it by checking their Message#editedTimestamp
.
Focus on the second packet:
{
"t": "MESSAGE_UPDATE",
"s": 87,
"op": 0,
"d": {
"webhook_id": "826343609824575504",
"type": 20,
"tts": false,
"timestamp": "2024-02-26T12:07:46.121000+00:00",
"position": 0,
"pinned": false,
"mentions": [],
"mention_roles": [],
"mention_everyone": false,
"member": {
"roles": [
"710374276049534977",
"986909666820898867",
"678176821321138189",
"742414428208758815"
],
"premium_since": null,
"pending": false,
"nick": "( b. ) Bloony 🌸",
"mute": false,
"joined_at": "2022-09-16T20:35:00.838000+00:00",
"flags": 0,
"deaf": false,
"communication_disabled_until": null,
"avatar": null
},
"interaction_metadata": {
"user_id": "676103178323886085",
"type": 2,
"name": "ping",
"id": "1211645782789201970",
"authorizing_integration_owners": {
"0": "678164358378946580"
}
},
"interaction": {
"user": {
"username": "bloonatics",
"public_flags": 4194432,
"id": "676103178323886085",
"global_name": "Bloonatics",
"discriminator": "0",
"avatar_decoration_data": null,
"avatar": "a236da7641db588ca84c75541a8c8759"
},
"type": 2,
"name": "ping",
"member": {
"roles": [
"756248495110881360",
"995756877075988570",
"986909666820898867"
],
"premium_since": null,
"pending": false,
"nick": "Bloonatics 🌸",
"mute": false,
"joined_at": "2020-04-24T06:59:30.136000+00:00",
"flags": 2,
"deaf": false,
"communication_disabled_until": null,
"avatar": null
},
"id": "1211645782789201970"
},
"id": "1211645783686782996",
"flags": 0,
"embeds": [
{
"type": "rich",
"title": "Pong!",
"footer": {
"text": "bloonatics",
"proxy_icon_url": "https://images-ext-2.discordapp.net/external/xRotzEa3IhzPRr5ah464AOJarA5gfjVMDeDuFVvr4ng/https/cdn.discordapp.com/avatars/676103178323886085/a236da7641db588ca84c75541a8c8759.webp",
"icon_url": "https://cdn.discordapp.com/avatars/676103178323886085/a236da7641db588ca84c75541a8c8759.webp"
},
"description": "Roundtrip latency: `241ms`\nWebsocket heartbeat: `74ms`",
"color": 12845022
}
],
"edited_timestamp": "2024-02-26T12:07:46.412817+00:00",
"content": "",
"components": [],
"channel_id": "748114061966835772",
"author": {
"username": "Bloony",
"public_flags": 65536,
"premium_type": 0,
"id": "826343609824575504",
"global_name": null,
"discriminator": "0615",
"bot": true,
"avatar_decoration_data": null,
"avatar": "a_c7b487a96f23f21aac1a54125d821714"
},
"attachments": [],
"application_id": "826343609824575504",
"guild_id": "678164358378946580"
}
}
As we all know, this data is necessary and we want to handle it because its oldMsg
and newMsg
have a completely different Message
structure and Message#editedTimestamp
.
Focus on the third packet:
{
"t": "MESSAGE_UPDATE",
"s": 88,
"op": 0,
"d": {
"id": "1211645783686782996",
"channel_id": "748114061966835772",
"attachments": [],
"guild_id": "678164358378946580"
}
}
You probably know what I want to say already. Since the values of the previous packet are cached, we will receive oldMsg
and newMsg
with exactly the same Message
structure (I know that attachments
would be updated, but both are empty array in this case) and Message#editedTimestamp
(1708949266412
in this case). Therefore, we can ignore it with the same method.
from discord.js.
Related Issues (20)
- .toJSON() is 'unknown' HOT 1
- crashing after message deletion HOT 5
- Using channel.send on a channel where the bot has not the permission to post makes the whole program crash HOT 3
- Kicking the bot from its dev guild and inviting it again drops the slash commands HOT 6
- Automated Message nonce handling HOT 1
- Emit poll events on uncached messages
- `ws` throws `TypeError: Cannot use 'in' operator to search for 'code' in undefined` when with Deno HOT 6
- Wrong base URL for GIF stickers
- [Typing] `interaction.followUp()` should not have `ephemeral` in its options? HOT 6
- oops HOT 1
- Uncaught exception when adding member that is already part of the guild
- Readonly arrays in interfaces don't allow dynamically adding data
- Allow InteractionOptionResolvers to return the raw value for different option types (like user) HOT 4
- DiscordAPIError[10062]: Unknown interaction (AutoComplete) HOT 1
- Cannot add user option when using localizations HOT 3
- Bot can't enter the ready state in voice channels
- New Premium Button Style & Deep Linking URL Schemes HOT 2
- Conflict between discord.js + @nodes/types after upgrading HOT 20
- ws affected by a DoS when handling a request with many HTTP headers HOT 1
- update @discordjs/ws HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from discord.js.