Git Product home page Git Product logo

Comments (2)

Jiralite avatar Jiralite commented on June 23, 2024

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.

Bloonatics avatar Bloonatics commented on June 23, 2024

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 the edited label in their messages from Discord's UI). If you want to handle more complex MESSAGE_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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.