#Question about EventMessageDelete

127 messages · Page 1 of 1 (latest)

lusty drift
#

Hello,
Before opening this post, I asked a few members in the Discord Developers server about the MessageDelete event. I'm having a strange issue: they told me that Discord doesn't provide logs when a bot deletes a message (unless the bot deletes a large number of messages).

However, when I run my code and log the data from the MessageDelete event, for some unknown reason, it shows my ID instead of the ID of the person who actually deleted it. Even stranger, the log claims the user who sent the message deleted it themselves, which is incorrect because the bot deleted it.

I'm here to ask for help and to understand this, because the data I'm receiving is very confusing. Here is the code I'm using to fetch the user:


const fetchedLogs = await guild.fetchAuditLogs({
                type: AuditLogEvent.MessageDelete,
                limit: 1,
            });
            const deletionLog = fetchedLogs.entries.first();
            console.log("Valeur de deletionlog",deletionLog);

            let executorTag = `<@${oldMessage.author.id}>`;

            if (deletionLog) {
                const { executor, targetId, createdTimestamp, extra } =
                    deletionLog;
                const isRecent =
                    Math.abs(Date.now() - createdTimestamp) < 10_000;
                const isCorrectTarget = targetId === oldMessage.author.id;
                const isCorrectChannel =
                    extra?.channel?.id === oldMessage.channelId;
                if (isRecent && isCorrectTarget && isCorrectChannel) {
                    executorTag = `<@${executor?.id}>`;
                } else if (isRecent && isCorrectTarget) {
                    executorTag = `<@${executor?.id}>`;
                }
            }

Well for a strange reason he said the user in the data but the problem is that he log the wrong person who deleted i try and when the bot delete it he said that is the user who deleted it.

thorny salmonBOT
reef dove
#

to clear up confusion, this isn't "message delete event", because that talks about something quite a bit different

#

this is talking about an audit log entry for a message deletion

#

Question about MessageDelete audit log

#

second of all.. you're setting executorTag to always be the message author, and then you change it to something else that doesn't even have to be there

#

and when bots delete single message they don't produce audit logs for it

#

since there physically is no entry for it, you have to be fetching something else, as

which is incorrect because the bot deleted it.
will not be possible to be fetched

lusty drift
#

Hello, if I understand correctly, you're saying that MessageDelete isn't a message deletion event?

Secondly, I didn't understand the comment about the executor tag in my code. Since this event doesn't provide the executor, unlike other events such as GuildAuditLogEntryCreate, I'm a bit stuck if I can't retrieve the user.

Currently, from what I understand, the event still fires when the bot deletes a message. I don't know why, but this event isn't triggered in one command.

#

So i need to acces to the cache if i resume?

reef dove
#

up there in your code, you're not looking at any events, youre looking at audit log entries for message deletion

#

you're not even listening to audit log event (which is the GuildAuditLogEntryCreate you mention), you're fetching the audit log entries

#

the message delete event does fire for message deletions, that's how discord sends the data to connected people that this message should now disappear from their screens, and you can listen to that event with your bot. but as already said, it only has the absolute minimum of data required to achieve this

#

audit logs aren't a list of things that are happening.
audit logs are a list of auditable moderation actions that then can be read through to audit who did what and when

#

members deleting their own messages isn't a moderative action, and as such there's nothing to audit there

#

bots deleting single messages has been explicitly set by discord to not be put into audit logs, because bots can delete a lot of single messages simply during answering commands, and people running such commands a bunch would just be a massive clutter in the audit logs

lusty drift
# reef dove bots deleting single messages has been explicitly set by discord to not be put i...

Okay, I really misread the documentation, so sorry for wasting your time. However, I'm still confused. If I can't use MessageDelete to get the ID of the person who sent and deleted the message, it seems frustrating, especially since you mentioned an event that I assume should be able to track this. The problem is that GuildLogEntryCreate doesn't log anything, or at least it doesn't display anything. The only console.log that executes when I delete the message, as you indicated, is messageDelete.

So I suppose what I'm listening for, that is, fetchedLogs, isn't the correct method.

reef dove
#

that data is there

#

otherwise this wouldn't be able to show it

#

do note however, that audit log entries can get grouped together

#

if i go and delete 10 messages one by one, i won't have 10 "tipaka deleted a message" in the audit log, i will have one "tipaka deleted 10 messages"

#

they get grouped by channel and message author, and the audit log entry gets updated

#

i don't know the exact time limit for the grouping, but it's defeinitely at least a few minutes

lusty drift
lusty drift
#

So the oldmessage in the MessageDelete event provides all the information about the deleted message, including, as you said (and correct me if I'm wrong), the channel IDs, author, etc., as well as the content.

Then the fetch I perform gives almost everything, including the executor, the one that deletes it.

The only thing that confuses me, but I think you mentioned it, is a parameter in [serverManager.ts:434] [ServerManager] sweep end
Value of deletionlog GuildAuditLogsEntry, which gives us bot:false.

I assume this is due to the bulk deletion of messages.

I just don't understand why the event is triggered when the bot deletes, given that, as you explicitly stated, it shouldn't trigger the event, at least from what I understand.

reef dove
#

check what's in the actual audit logs by yourself

#

you can set the filter to message deletions and see what's the most recent one

#

and no, you're still misundarstanding

#

deleting messages has to be broadcasted to users so that they get messages deleted on their screen

#

that's done via messageDelete event

#

does not matter who deletes, it gets emitted

#

but you're then trying to fetch audit logs to see who caused that event to be emitted

#

and if a bot deleted a message, triggering the messageDelete event, there will not be an audit log for that

#

audit logs are not events

#

they're a discord-provided list of moderation things that had happened in the server

lusty drift
# reef dove check what's in the actual audit logs by yourself

Yeah i already do that and well idk if the tool translation say something weird but yes i just see and well the old Message just log the message of the user deleted.

So i am going to re understand so my fetch is not a good method for having who delete it.

And the bot can't be log but you said that discord-provided list can be helpfull, they are on the discord developer portal i guess?

reef dove
#

this is audit log

lusty drift
reef dove
#

it's a list

#

discord puts stuff there

#

that's what i meant by "discord-provided"

lusty drift
#

So the list are put in AuditLog.[And the type ?]

reef dove
#

the one you're interested in

#

but that only ever sets this

lusty drift
# reef dove the one you're interested in

So, the one who intereset me and when the user have got the message delete by and other user . So i just do 2 console.log One show the details of the message like what you mention the strict detail and the other like the fetch a bit confused but i have who deleted it

lusty drift
wanton skiff
#

. (Gonna re read the thread once again because i cant understand it .. lmao)

#

so , if someone deletes a message , you want to know who did it ?
(Si quelqun supprime un message tu veux savoir qui l'as supprimer?)

lusty drift
# wanton skiff so , if someone deletes a message , you want to know who did it ? (Si quelqun s...

Well yes but i having a big issue the result is not what i excepted i try to console.log the 2 parameter like oldMessage who as type OldMessage and the fetch .

The first okay just give the data of the message Destroy. The other one give to many information and when the bot delete just one the Event just show is head and say wrong data.

The person in discord developer portal say that we don't have log if is not a massive delete by the bot but well i just delete on message and bom a log and i don't know how to face it i try severeal fix like the strange code but doesn't work so i just destroy it and keep a soft version but well same issue

|| Pas vraiment, j’ai déjà l’accès, seulement celui-ci devient très vite erroné lorsque le bot arrive.||

wanton skiff
#

tu peut continuer en francais si tu prefere lol

#

les event comme AuditLogCreate et MessageDelete , sont ...comment dire... compliquer

lusty drift
# wanton skiff tu peut continuer en francais si tu prefere lol

Ok merci j'avais du mal, pour faire simple je sais pas si vous avez vraiment tout compris vu comment mon anglais est très bancale.

Enfaite je fais ceci :


module.exports = {
    name: Events.MessageDelete,
    once: false,
    run: async (client: Client, oldMessage: Message) => {```

Pour vérifier les dires des membres du serveurs de discord Developer Portal et ici j'ai fait des console.log.

Dans un premier temps j'ai bien eu l'information du message détruit jusqu'a la j'avais compris

Mais le fetch est tellement étrange que je reçois pas seulement celui qui la détruit mais d'autres info comme ceci  : bot false et d'autres encore plus hallucinant 

Le soucis c'est que  visiblement lorsque le bot supprime un seul message sans l'utilisation de commande  celui-ci active l'event MessageDelete et renvoie une information erroné.

En effet j'ai pu voir que le MessageDelete est très compliqué.
wanton skiff
#

un fetch qui a beaucoup plus dinformation que nessesaire ... cest normal .. cest surement parce que tu log le fetch au complet ... non ? ... de ce que je peut voir ici en tout cas cest le truc au complet qui est log

#

mais a partir de la tu peut avoir toute ce que ta besoin pour log juste ce que ta besoin

lusty drift
wanton skiff
#

lorsque ton bot supprime un message , automatiquement levent va trigger

#

mais vu que cest lui qui la supprimer , ton executor va devenir ton bot

lusty drift
wanton skiff
#

hmmm....

#

envoie moi ton log pour voir ?

lusty drift
#

Oui je vais juste remettre en marche les logs

#

Je ne peux malheuresement pas transmettre l'embed car il contient un url mais la il indique que j'ai delete le message/

wanton skiff
#

887723443154456637 <- ca cest toi en effet
mais cest le bot qui la supprimer ?

lusty drift
#

Oui

#

Lorsque un lien d'invitation est détecter il le supprime

#

Et visiblement il n'a pas l'air d'apprécier la chose

wanton skiff
#

et dans discord cest quoi qui est marquer

lusty drift
#

oula, en effet rien

wanton skiff
#

voila 🙂

#

ya pas de data

lusty drift
#

Wow, je n'arrive pas a piger correctement. Discord déclenche un event sans envoyer de data?

wanton skiff
#

pour les message supprimer oui

#

car un message supprimer , discord veux qui reste supprimer

lusty drift
#

Je suis toujours confus j'arrive a log les messages supprimer lorsque un utilisateur le supprime d'un autre message ou de lui même mais avec le bot si je rejoins ce que vous dites il ne log rien

#

Dans ce cas je peux poser une question ? Vu que visiblement discord ne log rien qu'es ce que je récupére exactement? Car la j'ai des informations qui sont présentes erronées certes

wanton skiff
#

"Valeur de deletionlog GuildAuditLogsEntry {
targetType: 'Message',
actionType: 'Delete',
action: 72,"
ca ressemble a levenement AuditLogEntryCreate et non MessageDelete 🤔

lusty drift
#

Je vous assure que mon AuditLogEntryCreate ne couvre pas ce cas car j'ai pas mis.

Comme mentionner dans ce que vous avez envoyez "Valeur de deletionlog" vien du console.log uniquement activé dans l'event MessageDelete

#

ligne 24

wanton skiff
#

fetchedlog cest type auditLogEntry: GuildAuditLogsEntry<AuditLogEvent,.... Si ?

#

si oui , tu peut essayer de log fetchedlog.extra ?

lusty drift
#

GuildAuditLogsFetchOptions<AuditLogEvent.MessageDelete>.type?: AuditLogEvent.MessageDelete | undefined

ceci?

lusty drift
#

Wow attendez je me suis perdu

wanton skiff
#

Deletion log desoler

lusty drift
#

Oui alors lorsque j'ai fait console.log("Valeur de deletionlog",deletionLog?.extra); j'ai le extra qui apparait par contre TS me dit que celui-ci peut être null.

Vous me demandez a ce que je le log c'est bien cela?

wanton skiff
#

Oui

lusty drift
wanton skiff
#

ok et maintenant extra.messages ?

lusty drift
#

c'est a dire dans le deletionlog?.extra.message?

wanton skiff
#

Oui

lusty drift
#

il ne me proprose pas le type

wanton skiff
#

jveux juste voir si ta plus dinformation

#

messages

#

messages: GuildMessageManager { channel: [Circular *1] }

avec le s

lusty drift
#

"message": "Property 'messages' does not exist on type '{ channel: GuildTextBasedChannel | { id: string; }; count: number; }'.",
console.log("Valeur de deletionlog",deletionLog?.extra.messages);

wanton skiff
#

rahhhhhhh ...... x)

#

ca se peut que jreponde lentement , jessaye aussi de mon coter lol

lusty drift
# wanton skiff ca se peut que jreponde lentement , jessaye aussi de mon coter lol

Oui pas de soucis XD, de mon côté j'essaye tant bien que mal de regarder pourquoi c'est le basard sinon j'ai fouillé et trouver le type de extra :

GuildAuditLogsEntry<AuditLogEvent.MessageDelete, "Delete", "Message">.extra: {
channel: GuildTextBasedChannel | {
id: Snowflake;
};
count: number;
}
Visiblement le message n'a pas l'air d^tre présent

wanton skiff
#

Visiblement..

lusty drift
#

De ce que j'ai essayer le toJson pour voir ce que cela fait mais il renvoie toujours mon ID. C'est vraiment galére

wanton skiff
#

.... jpeut faire simple et envoyer mon event au complet pour auditlogcreate et essaye le ? joue avec genre ...

#

comme ca si sa fonctionne tu pourra le garder OMEGAlul

#

jai absolument toute les evennements

lusty drift
wanton skiff
#

le code que jai envoyer marchera suelement dans AuditLogEntryCreate

lusty drift
#

Ah j'avais pas fait gaffe AuditLogEntry?

#

je vais modifier quelque chose alors

#

Il y a quelque chose que j'ai pas compris dans le code vous faite auditLogEntry: GuildAuditLogsEntry autrement dit vous prenez le type de celui-ci ?

wanton skiff
#

je precise ce que cest car ...Typescript

lusty drift
#

Navrée de l'attente le code était pas compatible je vais eulement le test

wanton skiff
#

de la ligne 0 a 50 si cetais pas compatible cest un peu normale lol

#

les lignes 25 a 36 sont importante pour le reste du code parcontre jtavertis

#

(les 2 fonctions)

lusty drift
#

Alors comment dire

#

L'event MessageDelete ne s'active point

lusty drift
#

je vais casser quelque chose peut être que mon code bloque quelque chose

#

Malheuresement il ne log rien du tout

#

j'ai casser l'event MessageDelete séparé je croyais qu'il faisait un blocage mais non même en le // rien a faire il est silencieux

#

Visiblement en effectuant plusieurs test le GuildAuditLogEntryCreate ne gére visiblement pas le MessageDelete

wanton skiff
#

si ya pas de log dans discord tu aura pas de log dans ton code effectivement

lusty drift
#

Visiblement malgré toute mes tentative d'avoir quelque je tombe sur la même anomalie

#

Je n'arrive pas a comprendre si l'event est déclenché j'ai forcement l'id du bot qui a détruit le message