| D++ (DPP) C++ Discord API Bot Library

Search
Loading...
Searching...
No Matches
Webhooks

Webhooks are a simple way to post messages from other apps and websites into Discord. They allow getting automated messages and data updates sent to a text channel in your server. Read more in this article about Webhooks.

The following code shows how to send messages in a channel using a webhook.

#include <dpp/dpp.h>
#include <chrono>
#include <thread>
int main()
{
/* If you just want to fire webhooks, you can instantiate a cluster with no token */
dpp::cluster bot;
/* Start the cluster in its own thread */
bot.start(dpp::st_return);
/* Construct a webhook object using the URL you got from Discord */
dpp::webhook wh("https://discord.com/api/webhooks/833047646548133537/ntCHEYYIoHSLy_GOxPx6pmM0sUoLbP101ct-WI6F-S4beAV2vaIcl_Id5loAMyQwxqhE");
/* Send a message with this webhook asynchronously */
bot.execute_webhook(wh, dpp::message("Have a great time here :smile:"));
/* Wait here for the webhook to complete, but we could do anything we need here */
while (bot.active_requests() > 0) {
std::this_thread::sleep_for(std::chrono::seconds(1));
}
/* When we return here, the cluster will be terminated */
return 0;
}
dpp::cluster
The cluster class represents a group of shards and a command queue for sending and receiving commands...
Definition cluster.h:89
dpp::cluster::execute_webhook
void execute_webhook(const class webhook &wh, const struct message &m, bool wait=false, snowflake thread_id=0, const std::string &thread_name="", command_completion_event_t callback=utility::log_error())
Execute webhook.
dpp::cluster::start
void start(start_type return_after=st_wait)
Start the cluster, connecting all its shards.
dpp::cluster::active_requests
size_t active_requests()
Get the number of currently active HTTP(S) requests active in the cluster. This total includes all in...
dpp::webhook
Represents a discord webhook.
Definition webhook.h:59
dpp::st_return
@ st_return
Return immediately after starting shard threads. If you set the parameter of cluster::start() to this...
Definition cluster.h:82
dpp::message
Represents messages sent and received on Discord.
Definition message.h:2350

Note
  For just sending a webhook, the example above is overkill. If you are here because you searched for 'how to send a Discord webhook in C++', you'll quickly learn that D++ can do much more than just send webhooks! The above is just a very simple example. You can also send embed messages. All you have to do is to add an embed to the message you want to send. If you want to, you can also send it into a thread. For further examples, check the rest of the site.

D++ Library version 9.0.13 D++ Library version 9.0.12 D++ Library version 9.0.11 D++ Library version 9.0.10 D++ Library version 9.0.9 D++ Library version 9.0.8 D++ Library version 9.0.7 D++ Library version 9.0.6 D++ Library version 9.0.5 D++ Library version 9.0.4 D++ Library version 9.0.3 D++ Library version 9.0.2 D++ Library version 9.0.1 D++ Library version 9.0.0 D++ Library version 1.0.2 D++ Library version 1.0.1 D++ Library version 1.0.0