discord_add_intents - add events to listen to#

void discord_add_intents(struct discord *client, enum discord_gateway_intents code)#

Subscribe to Discord Events.

Parameters:
  • client – the client created with discord_init()

  • code – the intents opcode, can be set as a bitmask operation

Example#

discord_event_scheduler_t scheduler(struct discord *client,
                                    struct sized_buffer *data,
                                    enum discord_gateway_events event)
{
  switch (event) {
  case DISCORD_GATEWAY_EVENTS_MESSAGE_CREATE:
  case DISCORD_GATEWAY_EVENTS_MESSAGE_UPDATE: {
    struct discord_message msg;
    discord_message_from_json(data->start, data->size, &msg);

    struct discord_create_message_params params = {
      .content = "A message has been created or updated"
    };
    discord_create_message(client, msg.channel_id, &params, NULL);

    discord_message_cleanup(&msg);
  } return DISCORD_EVENT_IGNORE;
  default:
    return DISCORD_EVENT_MAIN_THREAD;
  }
}

int main(void)
{
  struct discord *client = discord_init(BOT_TOKEN);
  discord_add_intents(client, DISCORD_GATEWAY_GUILD_MESSAGES
                                | DISCORD_GATEWAY_DIRECT_MESSAGES);
  discord_set_event_scheduler(client, &scheduler);
  discord_run(client);
  discord_cleanup(client);
}