General library usage
Normal (authenticated) library usage:
- Initialize library with dscrd_initialize();
- Authenticate with DiscordClient_open (type, token), where type is one of token_type_e and token is your token string. You will get DiscordClient pointer in return. You will need it for dscrd library calls.
- Call library functions and receive other objects like Webhook.
- Free all objects you receive, for example use Webhook_destroy (Webhook) to free Webhooks.
- Close Discord session with DiscordClient_close (DiscordClient).
- Close library with dscrd_terminate();
Webhook-only (no-authentication) library usage:
- Initialize library with dscrd_initialize();
- Load your webhooks with no-auth functions like Webhook_get_no_auth() or Webhook_get_no_auth_url().
- Call webhook functions like Webhook_execute/modify/delete and so on.
- Free all allocated webhooks.
- Close library with dscrd_terminate();
Gateway API
Gateway API in dscrd library is optional. It can even be excluded from build. You can check if Gateway API was disabled by calling dscrd_has_gateway(). To use Gateway API with your DiscordClient you will need to initiate it with DiscordClient_gateway(). Function will return 0 on connection success. After you done it you can use all functions which use gateway. When you're finished no more action is needed except the usual DiscordClient_close().
Misc
- Use dscrd_error() to get error string for last function. Most of the time usage of this function will look like this:
if (!channel) {
printf (
"Receiving channel failed. %s\n",
dscrd_error());
return 1;
}
if (!user) {
return 1;
}
if (!webhook) {
printf (
"Receiving webhook failed. %s\n",
dscrd_error());
return 1;
}
If your code is pyramid-structured like, then you can use dscrd_error_long(). It will print exact function which failed. Example usage of dscrd_error_long() would look like this: int success = 0;
if (channel) {
if (user) {
if (webhook) {
success = 1;
...
Webhook_free (webhook);
}
DiscordUser_free (user);
}
DiscordChannel_free (channel);
}
if (!success) {
}