Discord Trigger icon

Discord Trigger

Discord Trigger on message

Overview

The Discord Trigger node listens for various events occurring within Discord servers (guilds) and channels, such as messages, reactions, role changes, and user join/leave events. It is designed to trigger workflows in n8n when these specific Discord events happen, enabling automation based on real-time Discord activity.

Common scenarios where this node is beneficial include:

  • Automating responses or actions when a message containing certain keywords or patterns is posted.
  • Tracking user joins or leaves to update databases or send welcome/goodbye messages.
  • Monitoring role creation, deletion, or updates to manage permissions or notify admins.
  • Reacting to message reactions to implement voting systems or reaction-based commands.

Practical examples:

  • Trigger a workflow when a user sends a direct message starting with "!help" to provide automated assistance.
  • Listen for new roles created on the server and log them into an external system.
  • Detect when a user adds a reaction to a message and update a leaderboard accordingly.

Properties

Name Meaning
Trigger Type The type of Discord event to listen for. Options include: Direct Message, Message, Reaction Add, Reaction Remove, Role Add, Role Delete, Role Update, User Join, User Leave, User Update.
Server Names or IDs Select one or more Discord servers (guilds) to listen to. You can choose from a list or specify IDs via expressions. Only applicable for most event types except interaction.
Listen To Channels Select text channels within the chosen servers to listen to for message or reaction events. If none selected, all channels are listened to. Requires bot credentials and at least one accessible channel.
Listen to Roles Optionally select roles to filter messages or reactions by role. If none selected, listens to @everyone.
Listen to Message For reaction add/remove events, specify a message ID to restrict triggers only to reactions on that message.
Pattern Defines how the message content is matched for message or direct message triggers. Options: Bot Mention, Contains, Ends With, Equals, Every, Regex, Starts With.
Value The string or regex pattern used to match messages according to the selected pattern. Required for most message/direct message patterns except "Every" and "Bot Mention".
Case Sensitive Whether the message matching is case sensitive. Defaults to false.
Trigger Only on Message Replies If enabled, the trigger activates only when the message is a reply to another message. The replied-to message will be included in the output.
Message ID For interaction triggers, specifies the message ID of the button or select menu to listen to.
Additional Fields Collection of optional fields:
• Trigger on Other Bot Input: whether to trigger on messages sent by other bots.
• Attachment(s) Required: whether the message must have at least one attachment to trigger.

Output

The node outputs JSON data representing the event details depending on the trigger type:

  • Message Events: Includes message ID, content, guild ID, channel ID, author ID and username, timestamp, whether the author is a bot, and optionally message reference details if it was a reply. Attachments are included if present.
  • User Join/Leave/Update Events: Outputs the full guild member object or updated member data.
  • Role Create/Delete/Update Events: Outputs role information; for updates, both old and new role data are provided with prefixed keys (old and new).
  • Reaction Add/Remove Events: Outputs combined reaction and user data along with channel and guild IDs.
  • Interaction Events: Not detailed here but would relate to button/select interactions by message ID.

If binary data were involved (e.g., attachments), it would be summarized accordingly, but this node primarily outputs JSON event data.

Dependencies

  • Requires a valid API authentication token credential for the Discord bot.
  • The bot must be running and connected to Discord with appropriate permissions to listen to the specified servers, channels, and events.
  • Uses inter-process communication (IPC) to connect to a bot process managing the Discord connection.
  • Requires n8n environment configured with the Discord bot credential and proper permissions granted to the bot on Discord.

Troubleshooting

  • No Token Given: If no API token is provided, the node will not connect and will log "No token given." Ensure the Discord bot credential is set up correctly.
  • Channel or Server Selection Errors: Selecting channels or roles without first selecting servers will cause errors. Always select at least one server before choosing dependent options.
  • Missing Permissions: The bot must have permission to read messages, view channels, and receive events for the selected servers and channels. Lack of permissions may result in no triggers firing.
  • Disconnected from IPC Server: The node logs disconnection errors if the IPC connection to the bot process is lost. Restarting the workflow or bot process may resolve this.
  • Workflow Activation Issues: If the workflow is stopped or deactivated, the bot disconnects automatically. Make sure the workflow is active to keep the bot connected.

Links and References

Discussion