Disconnect
Disconnects from Discord and closes the bot session, cleaning up resources.
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
info
If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.
Inputs
- Client Id - The Discord bot client identifier returned from the Connect node. This identifies which bot session to disconnect.
How It Works
The Disconnect node properly closes a Discord bot session and removes it from memory. When executed, the node:
- Validates the provided Client ID
- Retrieves the bot session associated with the Client ID
- Closes the Discord WebSocket connection
- Removes the session from the session manager
- Frees up system resources
Requirements
- A valid Client ID from a Connect node
- An active Discord bot session
Error Handling
The node will return specific errors in the following cases:
- ErrInvalidArg - Client ID is empty or missing
- ErrInvalidArg - Invalid Client ID (session not found)
Usage Notes
- Always use Disconnect when you're finished with Discord operations
- Disconnect frees up system resources and closes WebSocket connections
- After disconnecting, the Client ID becomes invalid
- You'll need to use Connect again to create a new session
- The session is automatically cleaned up when the flow stops, but it's best practice to explicitly disconnect
Best Practices
- Place a Disconnect node at the end of your Discord automation flow
- Use Try-Catch-Finally patterns to ensure Disconnect runs even if errors occur
- Don't reuse a Client ID after calling Disconnect
- For long-running bots, consider keeping the connection open instead of repeatedly connecting and disconnecting
Example Flow
Complete Discord automation with proper cleanup:
1. Connect node → Returns client_id
2. Send Channel Message node → Uses client_id
3. Get Channel Messages node → Uses client_id
4. Disconnect node → Uses client_id (cleanup)
Resource Management
Each active Discord bot session:
- Maintains a WebSocket connection to Discord
- Consumes system memory
- May have rate limits applied
Proper use of Disconnect helps:
- Prevent resource leaks
- Close unnecessary connections
- Keep your automation clean and efficient
- Avoid hitting Discord rate limits with idle connections
Error Handling Example
Use Try-Catch-Finally to ensure cleanup:
Try:
- Connect → client_id
- Discord operations using client_id
- (errors may occur here)
Finally:
- Disconnect → client_id
This ensures the connection is closed even if errors occur during operations.