0

So i was coding like a bot that detects if a channel got deleted, if it did i need the person so i can kick them with the bot. This was the code

client.on('channelDelete', async (channel) => {
    // Get the channel ID
    const channelDeleteId = channel.id;

    // Fetch all channel deletions from the audit log
    const auditLogs = await channel.guild.fetchAuditLogs({ type: 'CHANNEL_DELETE' });

    // Find the log entry for this specific channel
    const channelDeleteEntry = auditLogs.entries.find((entry) => entry.target.id === channelDeleteId);

    if (channelDeleteEntry) {
        const deleter = channelDeleteEntry.executor;
        console.log(`User ${deleter.username} deleted channel ${channel.name} at time ${channelDeleteEntry.createdAt}`);
    }
});

I tried asking people in discord and errors still appear, the error is DiscordAPIError[50035]: Invalid Form Body action_type[NUMBER_TYPE_COERCE]: Value "CHANNEL_DELETE" is not int.

Please help

New contributor
Nathan Liwang is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
0

1 Answer 1

1

The fetchAuditLogs() function is expecting a numeric value for the type: property rather than the string value you've used here. You maybe found an out of date tutorial or example for this function that was from a previous version. At some point the API was updated to use numeric values for an enumeration. The entire list of possibilities and their numeric values can be found here, but here's what that line of code should look like for you:

const auditLogs = await channel.guild.fetchAuditLogs({ type: 12 });

Sadly I don't deal with JavaScript enough to know if there's a way that you can access those values from the enumeration list like I would in C#. Perhaps someone can provide an edit/comment to include that. Having numbers you have to reference outside documentation to know what they mean is less than ideal.

1
  • Oh ok thank you, i will try using it Commented Jul 6 at 5:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.