discord_strerror() - return string describing ORCAcode value

group OrcaDiscordCodes

See

OrcaCodes for non-Discord errors

Defines

ORCA_DISCORD_JSON_CODE 1

Received a JSON error message

ORCA_DISCORD_BAD_AUTH 2

Bad authentication token

ORCA_DISCORD_RATELIMIT 3

Being ratelimited

ORCA_DISCORD_CONNECTION 4

Couldn’t establish connection to Discord

const char *discord_strerror(ORCAcode code, struct discord *client)

Return the meaning of ORCAcode.

Note

in case of a ORCA_DISCORD_JSON_CODE and if client is provided, a much more descriptive JSON message will be returned instead.

Parameters
  • code – the ORCAcode to be explained

  • client – the client created with discord_init(), NULL for generic error descriptions

Returns

a string containing the code meaning

Example

/* Attempt to send a message to a invalid channel (id 0) */
void on_force_error(struct discord *client,
                    const struct discord_message *msg)
{
  ORCAcode code = discord_create_message(client, 0, NULL, NULL);
  log_error("%s", discord_strerror(code, client));
}

int main(void)
{
  struct discord *client = discord_init(BOT_TOKEN);
  discord_set_on_command(client, "!force_error", &on_force_error);
  discord_run(client);
  discord_cleanup(client);
}