Action value: 1 | Target type: Guild

Action Details

Action Name
GUILD_UPDATE
Category
Server
Target Type
Guild
Action ID
1
Available Fields
nameiconsplashregionafk_channelafk_timeoutverification_level
// Discord.js v14+ - Fetch Audit Logs
const { AuditLogEvent } = require('discord.js');

// Fetch recent audit logs
const auditLogs = await guild.fetchAuditLogs({
  limit: 50, // Max 100
  type: AuditLogEvent.GUILD_UPDATE
});

// Access entries
for (const entry of auditLogs.entries.values()) {
  console.log(`Action: ${entry.action}`);
  console.log(`Executor: ${entry.executor.tag}`);
  console.log(`Target: ${entry.target}`);
  console.log(`Reason: ${entry.reason || 'No reason provided'}`);
  console.log(`Timestamp: ${entry.createdAt}`);

  // Access changes (for UPDATE actions)
  if (entry.changes) {
    for (const change of entry.changes) {
      console.log(`Changed ${change.key}: ${change.old} → ${change.new}`);
    }
  }
}

// Filter by user
const userLogs = await guild.fetchAuditLogs({
  user: '123456789012345678', // User ID
  type: AuditLogEvent.GUILD_UPDATE
});

// Find specific entry
const firstEntry = auditLogs.entries.first();
if (firstEntry) {
  console.log(`Most recent action by: ${firstEntry.executor.tag}`);
}
// Discord.js - Monitor Audit Logs
const { AuditLogEvent } = require('discord.js');

// Monitor for server settings were updated
setInterval(async () => {
  const auditLogs = await guild.fetchAuditLogs({
    limit: 1,
    type: AuditLogEvent.GUILD_UPDATE
  });

  const entry = auditLogs.entries.first();
  if (entry && entry.createdAt > lastChecked) {
    // New entry found
    console.log(`Server settings were updated`);
    console.log(`By: ${entry.executor.tag}`);
    console.log(`Target: ${entry.target}`);

    // Send to log channel
    const logChannel = guild.channels.cache.get('LOG_CHANNEL_ID');
    if (logChannel) {
      const embed = {
        color: 0xFF6F00,
        title: 'Server settings were updated',
        fields: [
          { name: 'Executor', value: `<@${entry.executor.id}>`, inline: true },
          { name: 'Target', value: entry.target?.toString() || 'Unknown', inline: true },
          { name: 'Reason', value: entry.reason || 'No reason provided' }
        ],
        timestamp: entry.createdAt
      };
      await logChannel.send({ embeds: [embed] });
    }

    lastChecked = entry.createdAt;
  }
}, 5000); // Check every 5 seconds

// Better approach: Listen to events and check audit logs
client.on('guildMemberRemove', async (member) => {
  // Wait a bit for audit log to be created
  await new Promise(resolve => setTimeout(resolve, 1000));

  const auditLogs = await member.guild.fetchAuditLogs({
    limit: 1,
    type: AuditLogEvent.MEMBER_KICK
  });

  const kickLog = auditLogs.entries.first();
  if (kickLog) {
    console.log(`${member.user.tag} was kicked by ${kickLog.executor.tag}`);
    console.log(`Reason: ${kickLog.reason || 'No reason'}`);
  }
});
💡

What are Audit Logs?

Audit logs track all administrative actions in a Discord server. They show who did what, when, and why. Requires "View Audit Log" permission. Logs are kept for 45 days.

Powered by Mamba Host