Weird behaviour from pins, caused by discord.js

i'm trying to register message pin updates I got it working functionally now, but i wondered why it's so "weird" when you pin a message the following happens: First an "MESSAGE_UPDATE" get's sent. in the payload it even says that the messge is pinned/not pinned (updated) Then an "CHANNEL_PINS_UPDATE" fires, which on djs get's emitted as ChannelPinsUpdate event. However, why doesn't the messageUpdate event trigger? I could simply do then (oldMessage.pinned !== newMessage.pinned) // got pinned/unpinned Why do i have to do in the ChannelPinsUpdate find message via audit log from channel
{
t: 'MESSAGE_CREATE',
s: 117,
op: 0,
d: {
pinned: false,
message_reference: {
type: 0,
message_id: '1255115609881182270',
guild_id: '1070626568260562954',
channel_id: '1218523493893935175'
},
id: '1255115611336609812',
// ... other fields
}
}
{
t: 'MESSAGE_UPDATE',
s: 121,
op: 0,
d: {
pinned: true,
id: '1255115609881182270',
// ... other fields
}
}
{
t: 'CHANNEL_PINS_UPDATE',
s: 122,
op: 0,
d: {
last_pin_timestamp: '2024-06-25T11:01:24+00:00',
channel_id: '1218523493893935175',
guild_id: '1070626568260562954'
}
}
{
t: 'MESSAGE_CREATE',
s: 123,
op: 0,
d: {
type: 6, // system message saying message got pinnned
// ... other fields
}
}
{
t: 'GUILD_AUDIT_LOG_ENTRY_CREATE', // audit log for the message
s: 124,
op: 0,
d: {
user_id: '498094279793704991',
target_id: '498094279793704991',
options: {
message_id: '1255115609881182270',
channel_id: '1218523493893935175'
},
id: '1255115626599678044',
action_type: 74,
guild_id: '1070626568260562954'
}
}
{
t: 'MESSAGE_CREATE',
s: 117,
op: 0,
d: {
pinned: false,
message_reference: {
type: 0,
message_id: '1255115609881182270',
guild_id: '1070626568260562954',
channel_id: '1218523493893935175'
},
id: '1255115611336609812',
// ... other fields
}
}
{
t: 'MESSAGE_UPDATE',
s: 121,
op: 0,
d: {
pinned: true,
id: '1255115609881182270',
// ... other fields
}
}
{
t: 'CHANNEL_PINS_UPDATE',
s: 122,
op: 0,
d: {
last_pin_timestamp: '2024-06-25T11:01:24+00:00',
channel_id: '1218523493893935175',
guild_id: '1070626568260562954'
}
}
{
t: 'MESSAGE_CREATE',
s: 123,
op: 0,
d: {
type: 6, // system message saying message got pinnned
// ... other fields
}
}
{
t: 'GUILD_AUDIT_LOG_ENTRY_CREATE', // audit log for the message
s: 124,
op: 0,
d: {
user_id: '498094279793704991',
target_id: '498094279793704991',
options: {
message_id: '1255115609881182270',
channel_id: '1218523493893935175'
},
id: '1255115626599678044',
action_type: 74,
guild_id: '1070626568260562954'
}
}
this is what client.on raw sends clearly a message update happend, with the new value of pinned even tho it "just got pinned" But discordjs doesn't fire the messageUpdate event (only the channelPinsUpdate and GuildAuditLogEntryCreate event)
7 Replies
d.js toolkit
d.js toolkit5mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by staff
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
Chrissy
ChrissyOP5mo ago
i have partials enabled, it's for both partial and not partial messages the message also get's automatically added to the cache, even when i clear it, but the event doesn't trigger
const pinAudit = cache.auditLog.getAudit(textChannel.guild?.id, AuditLogEvent.MessagePin).actions.filter(v => Date.now() - v.savedAt <= 750 && v.options.channel_id === textChannel.id).sort((a, b) => a.savedAt < b.savedAt ? 1 : a.savedAt > b.savedAt ? -1 : 0)[0];

const unPinAudit = cache.auditLog.getAudit(textChannel.guild?.id, AuditLogEvent.MessageUnpin).actions.filter(v => Date.now() - v.savedAt <= 750 && v.options.channel_id === textChannel.id).sort((a, b) => a.savedAt < b.savedAt ? 1 : a.savedAt > b.savedAt ? -1 : 0)[0];

const gotPinned = pinAudit ? true : unPinAudit ? false : null;

const auditData = pinAudit || unPinAudit || { options: { channel_id: null, message_id: null }, target: null, deleteAt: null, savedAt: null, executor: null, keyChanges: null, reason: null, id: null };

const author_id = auditData.target, { message_id, channel_id } = auditData.options;

if(message_id || author_id) {
const message = textChannel.messages.cache.get(message_id);
const fetched = !message ? await textChannel.messages.fetch(message_id).catch(() => null) : undefined;

console.log(`message by ${client.users.cache.get(author_id)?.username||"Unknown"} got ${typeof gotPinned === "boolean" ? gotPinned ? "pinned" : "unpinned" : "N/A"} - CACHE: ${message?.url||"N/A"} - FETCH: ${fetched?.url||"N/A"}`)
} else {
console.log("message pin updated happened...")
}
const pinAudit = cache.auditLog.getAudit(textChannel.guild?.id, AuditLogEvent.MessagePin).actions.filter(v => Date.now() - v.savedAt <= 750 && v.options.channel_id === textChannel.id).sort((a, b) => a.savedAt < b.savedAt ? 1 : a.savedAt > b.savedAt ? -1 : 0)[0];

const unPinAudit = cache.auditLog.getAudit(textChannel.guild?.id, AuditLogEvent.MessageUnpin).actions.filter(v => Date.now() - v.savedAt <= 750 && v.options.channel_id === textChannel.id).sort((a, b) => a.savedAt < b.savedAt ? 1 : a.savedAt > b.savedAt ? -1 : 0)[0];

const gotPinned = pinAudit ? true : unPinAudit ? false : null;

const auditData = pinAudit || unPinAudit || { options: { channel_id: null, message_id: null }, target: null, deleteAt: null, savedAt: null, executor: null, keyChanges: null, reason: null, id: null };

const author_id = auditData.target, { message_id, channel_id } = auditData.options;

if(message_id || author_id) {
const message = textChannel.messages.cache.get(message_id);
const fetched = !message ? await textChannel.messages.fetch(message_id).catch(() => null) : undefined;

console.log(`message by ${client.users.cache.get(author_id)?.username||"Unknown"} got ${typeof gotPinned === "boolean" ? gotPinned ? "pinned" : "unpinned" : "N/A"} - CACHE: ${message?.url||"N/A"} - FETCH: ${fetched?.url||"N/A"}`)
} else {
console.log("message pin updated happened...")
}
therefore i managed to create such a tool, to find the message that got pinned via channelPinsUpdate event. (a fetch is never required) But it could also be acomplished by triggering messageUpdate debug it:
client.on("raw", d => d.t !== "PRESENCE_UPDATE" && console.log(d));
client.on("channelPinsUpdate", () => console.log("channelPinsUpdate"));
client.on("messageUpdate", () => console.log("messageUpdate"));
client.on("raw", d => d.t !== "PRESENCE_UPDATE" && console.log(d));
client.on("channelPinsUpdate", () => console.log("channelPinsUpdate"));
client.on("messageUpdate", () => console.log("messageUpdate"));
on pin the messageUpdate never fires, but it's inside the raw event
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
Chrissy
ChrissyOP5mo ago
No description
Chrissy
ChrissyOP5mo ago
No description
Chrissy
ChrissyOP5mo ago
so when you pin a message for you the messageUpdate event triggers? reinstalling discord.js fixed it lol
Want results from more Discord servers?
Add your server