Audit Logs
Audit logs are Discord’s built-in system for tracking all administrative and moderation actions in your server. With DiSky, you can retrieve historical logs and listen to new actions in real-time.
What Are Audit Logs?
Section titled “What Are Audit Logs?”Audit logs record important actions that happen in your server:
- Member bans and kicks
- Message deletions
- Role changes
- Channel modifications
- Server settings updates
- And much more
Each log entry contains information about what happened, who did it, and when.
Required Setup
Section titled “Required Setup”Before working with audit logs, ensure your bot has the necessary permissions and intents:
-
Enable Gateway Intent
Add the
GUILD_MODERATIONintent to your bot:define new bot named "MyBot":intents: default intents, guild moderation intent -
Grant Bot Permission
Your bot needs the
VIEW_AUDIT_LOGSpermission in Discord:- Go to Server Settings > Roles
- Find your bot’s role
- Enable “View Audit Log”
Log Entry Properties
Section titled “Log Entry Properties”Each audit log entry contains:
| Property | Type | Description |
|---|---|---|
logged author | User | Who performed the action |
logged guild | Guild | Where it happened |
logged id | Text | Unique entry ID |
logged action | Text | What action was taken |
logged reason | Text | Why it was done (if provided) |
Fetching Audit Logs
Section titled “Fetching Audit Logs”Retrieve All Recent Logs
Section titled “Retrieve All Recent Logs”Get the most recent audit logs from a guild:
command /auditlogs: trigger: set {_guild} to event-guild
# Fetch logs retrieve audit logs from {_guild} and store them in {_logs::*}
# Display count reply with "Found %size of {_logs::*}% recent audit log entries"Loop Through Logs
Section titled “Loop Through Logs”Process each log entry:
command /recentactions: trigger: retrieve audit logs from event-guild and store them in {_logs::*}
make embed: set title of embed to "Recent Audit Log Actions" set embed color of embed to blue
loop {_logs::*}: set {_entry} to loop-value
# Get log details set {_author} to logged author of {_entry} set {_action} to logged action of {_entry} set {_reason} to logged reason of {_entry}
# Add to embed if {_reason} is set: set {_text} to "%{_action}% - Reason: %{_reason}%" else: set {_text} to "%{_action}% - No reason provided"
add field named mention tag of {_author} with value {_text} to fields of embed
# Limit to first 10 entries if loop-index is 10: stop loop
reply with last embedListening to New Logs
Section titled “Listening to New Logs”Instead of fetching logs manually, listen for new audit log entries in real-time:
on guild log create: # Get the log entry set {_entry} to event-logentry
# Extract information set {_author} to logged author of {_entry} set {_guild} to logged guild of {_entry} set {_action} to logged action of {_entry} set {_reason} to logged reason of {_entry} set {_id} to logged id of {_entry}
# Send notification to mod channel set {_modChannel} to text channel with id "MOD_CHANNEL_ID"
make embed: set title of embed to "🔍 Audit Log: %{_action}%" add field named "Moderator" with value mention tag of {_author} to fields of embed
if {_reason} is set: add field named "Reason" with value {_reason} to fields of embed else: add field named "Reason" with value "No reason provided" to fields of embed
add field named "Log ID" with value {_id} to fields of embed set timestamp of embed to now set embed color of embed to orange
post last embed to {_modChannel}Practical Examples
Section titled “Practical Examples”Ban Logger
Section titled “Ban Logger”Track all bans with details:
on guild log create: set {_action} to logged action of event-logentry
if {_action} contains "BAN": set {_moderator} to logged author of event-logentry set {_reason} to logged reason of event-logentry set {_guild} to logged guild of event-logentry
# Send to ban log channel set {_logChannel} to text channel with id "BAN_LOG_CHANNEL_ID"
make embed: set title of embed to "🔨 Member Banned" add field named "Moderator" with value mention tag of {_moderator} to fields of embed
if {_reason} is set: add field named "Reason" with value {_reason} to fields of embed else: add field named "Reason" with value "No reason provided" to fields of embed
set embed color of embed to red set timestamp of embed to now set footer of embed to "Guild: %discord name of {_guild}%"
post last embed to {_logChannel}Message Deletion Tracker
Section titled “Message Deletion Tracker”Monitor message deletions:
on guild log create: set {_action} to logged action of event-logentry
if {_action} contains "DELETE" and {_action} contains "MESSAGE": set {_moderator} to logged author of event-logentry set {_reason} to logged reason of event-logentry
set {_logChannel} to text channel with id "MESSAGE_LOG_CHANNEL_ID"
make embed: set title of embed to "🗑️ Message Deleted by Moderator" add field named "Deleted by" with value mention tag of {_moderator} to fields of embed add field named "Reason" with value {_reason} ? "Not specified" to fields of embed set embed color of embed to orange set timestamp of embed to now
post last embed to {_logChannel}Role Change Monitor
Section titled “Role Change Monitor”Track role assignments and removals:
on guild log create: set {_action} to logged action of event-logentry
if {_action} contains "ROLE": set {_moderator} to logged author of event-logentry set {_reason} to logged reason of event-logentry set {_guild} to logged guild of event-logentry
set {_logChannel} to text channel with id "ROLE_LOG_CHANNEL_ID"
make embed: set title of embed to "👑 Role Modified" set description of embed to "Action: %{_action}%" add field named "Moderator" with value mention tag of {_moderator} to fields of embed
if {_reason} is set: add field named "Reason" with value {_reason} to fields of embed
set embed color of embed to purple set timestamp of embed to now
post last embed to {_logChannel}Complete Audit Log System
Section titled “Complete Audit Log System”Comprehensive logging for all actions:
on guild log create: set {_entry} to event-logentry set {_action} to logged action of {_entry} set {_author} to logged author of {_entry} set {_reason} to logged reason of {_entry} set {_guild} to logged guild of {_entry}
# Determine log channel and color based on action type if {_action} contains "BAN" or {_action} contains "KICK": set {_channel} to "BAN_LOG_CHANNEL" set {_color} to red set {_emoji} to "🔨"
else if {_action} contains "DELETE": set {_channel} to "DELETE_LOG_CHANNEL" set {_color} to orange set {_emoji} to "🗑️"
else if {_action} contains "ROLE": set {_channel} to "ROLE_LOG_CHANNEL" set {_color} to purple set {_emoji} to "👑"
else if {_action} contains "CHANNEL": set {_channel} to "CHANNEL_LOG_CHANNEL" set {_color} to blue set {_emoji} to "📝"
else: set {_channel} to "GENERAL_LOG_CHANNEL" set {_color} to gray set {_emoji} to "📋"
# Get the log channel set {_logChannel} to text channel with id {_channel}
if {_logChannel} is not set: stop
# Create log embed make embed: set title of embed to "%{_emoji}% %{_action}%" add field named "Moderator" with value mention tag of {_author} to fields of embed
if {_reason} is set: add field named "Reason" with value {_reason} to fields of embed else: add field named "Reason" with value "No reason provided" to fields of embed
add field named "Log ID" with value logged id of {_entry} to fields of embed set embed color of embed to {_color} set timestamp of embed to now set footer of embed to discord name of {_guild}
post last embed to {_logChannel}Audit Log Search
Section titled “Audit Log Search”Search for specific actions:
command /searchlogs <text>: trigger: set {_query} to arg-1 retrieve audit logs from event-guild and store them in {_logs::*}
clear {_matches::*}
loop {_logs::*}: set {_action} to logged action of loop-value
if {_action} contains {_query}: add loop-value to {_matches::*}
if {_matches::*} is not set: reply with "No logs found matching '%{_query}%'" stop
make embed: set title of embed to "Search Results: %{_query}%" set description of embed to "Found %size of {_matches::*}% matching entries" set embed color of embed to blue
loop {_matches::*}: set {_author} to logged author of loop-value set {_action} to logged action of loop-value
add field named "%{_action}%" with value "By: %mention tag of {_author}%" to fields of embed
if loop-index is 10: stop loop
reply with last embedModeration Statistics
Section titled “Moderation Statistics”Track moderation activity:
command /modstats: trigger: retrieve audit logs from event-guild and store them in {_logs::*}
# Count actions per moderator clear {_modCounts::*} clear {_actionCounts::*}
loop {_logs::*}: set {_author} to logged author of loop-value set {_authorId} to discord id of {_author} set {_action} to logged action of loop-value
add 1 to {_modCounts::%{_authorId}%} add 1 to {_actionCounts::%{_action}%}
# Build statistics make embed: set title of embed to "📊 Moderation Statistics" set description of embed to "Recent activity breakdown"
# Top moderators clear {_modList::*} loop {_modCounts::*}: set {_mod} to user with id loop-index add "%mention tag of {_mod}%: %loop-value% actions" to {_modList::*}
if size of {_modList::*} > 0: add field named "Most Active Moderators" with value join first 5 elements of {_modList::*} with nl to fields of embed
# Action breakdown clear {_actionList::*} loop {_actionCounts::*}: add "%loop-index%: %loop-value%" to {_actionList::*}
if size of {_actionList::*} > 0: add field named "Actions Taken" with value join first 5 elements of {_actionList::*} with nl to fields of embed
set embed color of embed to green set timestamp of embed to now
reply with last embedBest Practices
Section titled “Best Practices”-
Dedicated Log Channels
Create separate channels for different log types (bans, deletions, role changes).
-
Require Reasons
Encourage moderators to always provide reasons for actions.
-
Regular Review
Check audit logs regularly to ensure proper moderation.
-
Alert on Important Actions
Notify admin roles when critical actions occur (bans, server setting changes).
-
Archive Old Logs
Discord keeps audit logs for 45 days. Consider backing up important entries.
-
Protect Log Channels
Make log channels visible only to moderators and admins.
-
Monitor Moderators
Track moderator activity to ensure consistent, fair moderation.
Common Action Types
Section titled “Common Action Types”Audit logs track many action types:
MEMBER_BAN_ADD- Member bannedMEMBER_BAN_REMOVE- Member unbannedMEMBER_KICK- Member kickedMESSAGE_DELETE- Message deletedMESSAGE_BULK_DELETE- Multiple messages deletedROLE_CREATE- Role createdROLE_UPDATE- Role modifiedROLE_DELETE- Role deletedCHANNEL_CREATE- Channel createdCHANNEL_UPDATE- Channel modifiedCHANNEL_DELETE- Channel deleted- And many more…
Troubleshooting
Section titled “Troubleshooting”No Logs Appearing
Section titled “No Logs Appearing”Problem: Audit logs are empty or not showing.
Solutions:
- Verify bot has
GUILD_MODERATIONintent enabled - Check bot has
VIEW_AUDIT_LOGSpermission - Ensure logs exist (Discord keeps them for 45 days)
- Confirm you’re checking the correct guild
Event Not Triggering
Section titled “Event Not Triggering”Problem: on guild log create event doesn’t fire.
Solutions:
- Enable
GUILD_MODERATIONintent in bot structure - Grant
VIEW_AUDIT_LOGSpermission to bot - Reload your script after adding the intent
- Verify the action you’re testing creates an audit log
Missing Reasons
Section titled “Missing Reasons”Problem: Logged reason is always null.
Explanation: Many actions don’t include reasons. Only actions taken through Discord’s UI or API with explicit reasons will have this field populated.
Solution: Encourage moderators to provide reasons when performing actions.
Wrong Author
Section titled “Wrong Author”Problem: Logged author shows the wrong user.
Explanation: The logged author is whoever performed the action (bot or user). For bot actions triggered by users, the bot is the author.
Solution: Store the original user separately if you need to track who initiated a bot action.
Audit Log Limits
Section titled “Audit Log Limits”- Retention: Discord keeps audit logs for 45 days
- Fetch limit: Up to 100 entries per request by default
- Rate limits: Standard API rate limits apply
- Permission required:
VIEW_AUDIT_LOGS - Intent required:
GUILD_MODERATION
Next Steps
Section titled “Next Steps”- Set up AutoMod for automatic moderation
- Create Forum Channels for organized discussions
- Configure Welcome Screens for new members
- Learn about Error Handling for robust logging