Skip to main content

Introduction

NapCat implements the OneBot 11 event system to notify your application about various activities in QQ. Events are sent to your bot via the configured network adapter (HTTP POST, WebSocket, or Webhook) whenever something happens.

Event Structure

All OneBot 11 events share a common base structure:
number
required
Unix timestamp (in seconds) when the event occurred
number
required
The bot’s QQ number
string
required
The type of event. Possible values:
  • message - Message events
  • message_sent - Message sent by the bot
  • notice - Notice events
  • request - Request events
  • meta_event - Meta events (heartbeat, lifecycle)

Event Types

Message Events

Message events are triggered when the bot receives a message. There are two main types:
  • Private Messages - Direct messages from friends or temporary chats
  • Group Messages - Messages in group chats
Learn more in Message Events.

Notice Events

Notice events inform your bot about various activities and changes:
  • Group member changes (join, leave, kick)
  • Admin status changes
  • Group file uploads
  • Message recalls
  • Friend additions
  • Poke/nudge actions
  • Group bans and mutes
  • And many more
Learn more in Notice Events.

Request Events

Request events occur when someone wants to interact with the bot:
  • Friend requests
  • Group invitations
  • Group join requests
Learn more in Request Events.

Meta Events

Meta events provide information about the bot’s status:
  • Heartbeat - Periodic status updates
  • Lifecycle - Bot startup and shutdown events

Receiving Events

HTTP POST

When using HTTP POST adapter, events are sent as POST requests to your configured URL:

WebSocket

With WebSocket adapter, events are pushed to connected clients in real-time:

Webhook

Webhook works similarly to HTTP POST but with additional configuration options for authentication and filtering.

Event Handling Best Practices

1. Check Event Types

Always check the post_type field to determine how to handle the event:

2. Use Sub-types for Specific Logic

Most events have a sub-type field for more granular handling:

3. Handle Errors Gracefully

Always implement error handling for event processing:

4. Respond to Events

Some events support quick operations by returning a response:

Example: Complete Event Handler

Here’s a complete example of handling different event types:

Next Steps