![]() |
D++ (DPP)
C++ Discord API Bot Library
|
D++ gives you two ways to handle Discord events: sharding via websockets (the default) and webhooks. Websocket shards connect to Discord, handle up to 2,500 servers each, and process events asynchronously via a REST API call. Webhooks, on the other hand, let Discord push events straight to your bot, skipping the extra API call and making responses instant. WebSockets are great for most bots, but webhooks are super efficient for massive bots, using fewer resources while handling tons of traffic. The recommended setup is to run Nginx or Apache as a reverse proxy in front of your D++ bot, ensuring security and scalability. Enabling webhooks is simple—just call a method in your bot to activate them. We’ll guide you through setting it up step by step.
A simple summary of this process and how it differs is shown below:
There are advantages and disadvantages to a shardless webhook bot, the main ones are:
Advantages | Disadvantages |
---|---|
✅ Scales without restarts, any cluster can service any request ✅ Can be highly scalable on demand using a load balancer ✅ Can be scaled and proxied by cloudflare and other free services ✅ No need to keep shards connected, saving resources | ❎ Only slash commands and other components interactions can be used as entry points to the bot. Other events do not fire. ❎ Special consideration needs to be given to request/response flow. ❎ Without shards you don't have cache, so must rely entirely on resolved data and API calls. |
The first step is actually the easiest; enabling websocket event support in D++ is as simple as one method call, and specific parameters when initialising the cluster.bot
Please see the example below:
Note that you can get the public key from your application settings in the Discord Developer Portal. It is not your bot token!
event.reply()
. You can always acknowledge the response with event.thinking()
and edit the interaction later, but this must be done in a separate flow, NOT within the slashcommand event. This is because when you are in the event handler you are directly building a HTTP response that is directly sent back to Discord in an established HTTP request. You can follow up with other API calls if you wish later on. Each request is placed into D++'s thread pool, so you don't have to worry too much about blocking for a little while but remember users expect snappy responses and Discord have a 3 second hard limit on replies!Next, you should set up a reverse proxy using Nginx or Apache to forward requests from a public-facing HTTPS endpoint to a Discord bot listening on localhost:3000
. Discord mandates that all webhook endpoints for interactions must be HTTPS with a valid non self-signed certificate.
We will use a free Let's Encrypt certificate for SSL on the proxy, while allowing the bot itself to run using plaintext or self-signed SSL.
example.com
) pointing to your servercertbot
installed for Let's Encrypt SSLCreate a new configuration file:
Paste the following for plaintext (http) bot communication:
If the bot uses self-signed SSL, modify proxy_pass
:
Enable the site and restart Nginx:
Certbot will automatically update the Nginx configuration for HTTPS.
Paste the following for plaintext (http) bot communication:
If the bot uses self-signed SSL, update it as follows:
Enable the site and restart Apache:
Finally, to enable your Discord bot to receive interactions such as slash commands, you need to update Discord with the URL you set up above.
This involves configuring the Interactions Endpoint URL in your Discord application's settings.
https://example.com/interactions
).PING
request to verify the endpoint. D++ will ensure your bot replies appropriately.You can find even more information on Discord's official documentation on Setting Up an Interaction Endpoint.