Orca
A bot framework that is easy to reason about, easy to debug, and easy to use.
discord.h
Go to the documentation of this file.
1 
12 #ifndef DISCORD_H
13 #define DISCORD_H
14 
15 #include <stdbool.h>
16 #include "json-actor-boxed.h"
17 #include "logconf.h"
18 
19 
20 #define DISCORD_API_BASE_URL "https://discord.com/api/v9"
21 #define DISCORD_GATEWAY_URL_SUFFIX "?v=9&encoding=json"
22 #define DISCORD_VOICE_CONNECTIONS_URL_SUFFIX "?v=4"
23 
24 /* FORWARD DECLARATIONS */
25 struct discord;
27 
28 typedef uint64_t u64_unix_ms_t;
29 
30 /* SNOWFLAKES
31 https://discord.com/developers/docs/reference#snowflakes */
32 typedef uint64_t u64_snowflake_t;
33 #define SNOWFLAKE_INCREMENT 12
34 #define SNOWFLAKE_PROCESS_ID 17
35 #define SNOWFLAKE_INTERNAL_WORKER_ID 22
36 #define SNOWFLAKE_TIMESTAMP 64
37 
38 /* Size limits discovered from Discord docs and across the web */
39 #define MAX_NAME_LEN 100 + 1
40 #define MAX_TOPIC_LEN 1024 + 1
41 #define MAX_DESCRIPTION_LEN 2048 + 1
42 #define MAX_USERNAME_LEN 32 + 1
43 #define MAX_DISCRIMINATOR_LEN 4 + 1
44 #define MAX_SHA256_LEN 1024 + 1
45 #define MAX_LOCALE_LEN 16 + 1
46 #define MAX_EMAIL_LEN 254 + 1
47 #define MAX_REGION_LEN 16 + 1
48 #define MAX_REASON_LEN 512 + 1
49 #define MAX_MESSAGE_LEN 4000 + 1
50 #define MAX_PAYLOAD_LEN 4096 + 1
51 
52 /* EMBED LIMITS
53 https://discord.com/developers/docs/resources/channel#embed-limits */
54 #define EMBED_TITLE_LEN 256 + 1
55 #define EMBED_DESCRIPTION_LEN 2048 + 1
56 #define EMBED_MAX_FIELDS 25
57 #define EMBED_FIELD_NAME_LEN 256 + 1
58 #define EMBED_FIELD_VALUE_LEN 1024 + 1
59 #define EMBED_FOOTER_TEXT_LEN 2048 + 1
60 #define EMBED_AUTHOR_NAME_LEN 256 + 1
61 
62 /* WEBHOOK LIMITS
63 https://discord.com/developers/docs/resources/webhook#create-webhook */
64 #define WEBHOOK_NAME_LEN 80 + 1
65 
66 // specs/discord for generated code specs
67 #include "specs-code/discord/all_opaque_struct.h"
68 #include "specs-code/discord/all_enums.h"
69 #include "specs-code/discord/all_structs.h"
70 #include "specs-code/discord/all_functions.h"
71 
78 typedef void (*idle_cb)(struct discord *client, const struct discord_user *bot);
79 
87 typedef void (*event_raw_cb)(
88  struct discord *client,
89  enum discord_gateway_events event,
90  struct sized_buffer *sb_bot,
91  struct sized_buffer *event_data);
92 
100 typedef void (*guild_role_cb)(
101  struct discord *client, const struct discord_user *bot,
102  const u64_snowflake_t guild_id,
103  const struct discord_permissions_role *role);
110 typedef void (*guild_role_delete_cb)(
111  struct discord *client, const struct discord_user *bot,
112  const u64_snowflake_t guild_id,
113  const u64_snowflake_t role_id);
114 
122 typedef void (*guild_member_cb)(
123  struct discord *client, const struct discord_user *bot,
124  const u64_snowflake_t guild_id,
125  const struct discord_guild_member *member);
132 typedef void (*guild_member_remove_cb)(
133  struct discord *client, const struct discord_user *bot,
134  const u64_snowflake_t guild_id,
135  const struct discord_user *user);
136 
144 typedef void (*guild_ban_cb)(
145  struct discord *client, const struct discord_user *bot,
146  const u64_snowflake_t guild_id,
147  const struct discord_user *user);
148 
156 typedef void (*message_cb)(
157  struct discord *client, const struct discord_user *bot,
158  const struct discord_message *message);
159 typedef void (*sb_message_cb)(
160  struct discord *client, const struct discord_user *bot,
161  struct sized_buffer *sb_bot,
162  const struct discord_message *message,
163  struct sized_buffer *msg_payload);
164 
171 typedef void (*message_delete_cb)(
172  struct discord *client, const struct discord_user *bot,
173  const u64_snowflake_t id,
174  const u64_snowflake_t channel_id,
175  const u64_snowflake_t guild_id);
182 typedef void (*message_delete_bulk_cb)(
183  struct discord *client, const struct discord_user *bot,
184  const NTL_T(ja_u64) ids,
185  const u64_snowflake_t channel_id,
186  const u64_snowflake_t guild_id);
187 
196 typedef void (*channel_cb)(
197  struct discord *client, const struct discord_user *bot,
198  const struct discord_channel *channel);
205 typedef void (*channel_pins_update_cb)(
206  struct discord *client, const struct discord_user *bot,
207  const u64_snowflake_t guild_id,
208  const u64_snowflake_t channel_id,
209  const u64_unix_ms_t last_pin_timestamp);
210 
216 typedef void (*message_reaction_add_cb)(
217  struct discord *client, const struct discord_user *bot,
218  const u64_snowflake_t user_id,
219  const u64_snowflake_t channel_id,
220  const u64_snowflake_t message_id,
221  const u64_snowflake_t guild_id,
222  const struct discord_guild_member *member,
223  const struct discord_emoji *emoji);
230  struct discord *client, const struct discord_user *bot,
231  const u64_snowflake_t user_id,
232  const u64_snowflake_t channel_id,
233  const u64_snowflake_t message_id,
234  const u64_snowflake_t guild_id,
235  const struct discord_emoji *emoji);
242  struct discord *client, const struct discord_user *bot,
243  const u64_snowflake_t channel_id,
244  const u64_snowflake_t message_id,
245  const u64_snowflake_t guild_id);
252  struct discord *client, const struct discord_user *bot,
253  const u64_snowflake_t channel_id,
254  const u64_snowflake_t message_id,
255  const u64_snowflake_t guild_id,
256  const struct discord_emoji *emoji);
257 
263 typedef void (*voice_state_update_cb)(
264  struct discord *client, const struct discord_user *bot,
265  const struct discord_voice_state *voice_state);
271 typedef void (*voice_server_update_cb)(
272  struct discord *client, const struct discord_user *bot,
273  const char *token,
274  const u64_snowflake_t guild_id,
275  const char *endpoint);
276 
283  char url[1024];
284  int shards;
285 
286  int total;
287  int remaining;
290 
293 
295 
297 };
298 
303  u64_snowflake_t around;
304  u64_snowflake_t before;
305  u64_snowflake_t after;
306  int limit; // max number of messages (1-100)
307 };
308 
315  // common to @b application/json and @b multipart/form-data parameters
316  char *content;
317  char *nonce;
318  bool tts;
319 
320  // parameters for @b application/json
321  struct discord_embed *embed;
322  struct discord_channel_allowed_mentions *allowed_mentions;
323  struct discord_message_reference *message_reference;
324 
325  // parameters for @b multipart/form-data
326  // @note if just name field is set, will search for file in working directory
327  struct { // FILE STRUCT
328  char *name;
329  char *content;
330  size_t size;
331  } file;
332  char *payload_json;
333 };
334 
339  char *content;
340  struct discord_embed *embed;
341  enum discord_message_flags_code *flags;
342  struct discord_channel_allowed_mentions *allowed_mentions;
343 };
344 
349  int limit;
351 };
352 
353 
354  /* * * * * * * * * * * * * * * */
355 /* * * * CLIENT FUNCTIONS * * * */
356 
360 void discord_global_init();
361 
366 
373 struct discord* discord_init(const char token[]);
374 
381 struct discord* discord_config_init(const char config_file[]);
382 
388 void discord_cleanup(struct discord *client);
389 
397 void discord_add_intents(struct discord *client, enum discord_gateway_intents code);
398 
407 void discord_remove_intents(struct discord *client, enum discord_gateway_intents code);
408 
418 void discord_set_prefix(struct discord *client, char *prefix);
419 
430 void discord_set_on_command(struct discord *client, char *command, message_cb callback);
431 
440 void discord_set_on_event_raw(struct discord *client, event_raw_cb callback);
441 
448 void discord_set_on_idle(struct discord *client, idle_cb callback);
449 
457 void discord_set_on_guild_role_create(struct discord *client, guild_role_cb callback);
465 void discord_set_on_guild_role_update(struct discord *client, guild_role_cb callback);
473 void discord_set_on_guild_role_delete(struct discord *client, guild_role_delete_cb callback);
481 void discord_set_on_guild_member_add(struct discord *client, guild_member_cb callback);
489 void discord_set_on_guild_member_update(struct discord *client, guild_member_cb callback);
505 void discord_set_on_guild_ban_add(struct discord *client, guild_ban_cb callback);
513 void discord_set_on_guild_ban_remove(struct discord *client, guild_ban_cb callback);
521 void discord_set_on_channel_create(struct discord *client, channel_cb callback);
529 void discord_set_on_channel_update(struct discord *client, channel_cb callback);
537 void discord_set_on_channel_delete(struct discord *client, channel_cb callback);
553 void discord_set_on_message_create(struct discord *client, message_cb callback);
554 void discord_set_on_sb_message_create(struct discord *client, sb_message_cb callback);
562 void discord_set_on_message_update(struct discord *client, message_cb callback);
563 void discord_set_on_sb_message_update(struct discord *client, sb_message_cb callback);
571 void discord_set_on_message_delete(struct discord *client, message_delete_cb callback);
572 /*
573  * @brief Set a callback that triggers when a bulk of messages are deleted
574  *
575  * @param client the client created with discord_init()
576  * @param callback the callback that will be executed
577  * @note this function will automatically set intent(s) to make the callback triggerable
578  */
579 void discord_set_on_message_delete_bulk(struct discord *client, message_delete_bulk_cb callback);
619 void discord_set_on_ready(struct discord *client, idle_cb callback);
642 void discord_set_voice_cbs(struct discord *client, struct discord_voice_cbs *callbacks);
643 
648 };
649 
650 void discord_set_blocking_event_handler(struct discord *client, enum discord_event_handling_mode (*f)(void *cxt));
651 
657 void discord_run(struct discord *client);
658 
669 void* discord_set_data(struct discord *client, void *data);
670 
680 void* discord_get_data(struct discord *client);
681 
690 void discord_replace_presence(struct discord *client, struct discord_gateway_status_update *presence);
691 
700 void discord_set_presence(struct discord *client, struct discord_gateway_activity *activity, char status[], bool afk);
701 
702 
703  /* * * * * * * * * * * * * * * * */
704 /* * * * ENDPOINT FUNCTIONS * * * */
705 
706 // AUDIT LOG ENDPOINTS
707 ORCAcode discord_get_guild_audit_log(struct discord *client, const u64_snowflake_t guild_id, struct discord_get_guild_audit_log_params *params, struct discord_audit_log *p_audit_log);
708 
709 // CHANNEL ENDPOINTS
710 ORCAcode discord_get_channel(struct discord *client, const u64_snowflake_t channel_id, struct discord_channel *p_channel);
711 ORCAcode discord_modify_channel(struct discord *client, const u64_snowflake_t channel_id, struct discord_modify_channel_params *params, struct discord_channel *p_channel);
712 ORCAcode discord_delete_channel(struct discord *client, const u64_snowflake_t channel_id, struct discord_channel *p_channel);
713 ORCAcode discord_get_channel_messages(struct discord *client, const u64_snowflake_t channel_id, struct discord_get_channel_messages_params *params, NTL_T(struct discord_message) *p_messages);
714 ORCAcode discord_get_channel_message(struct discord *client, const u64_snowflake_t channel_id, const u64_snowflake_t message_id, struct discord_message *p_message);
715 ORCAcode discord_create_message(struct discord *client, const u64_snowflake_t channel_id, struct discord_create_message_params *params, struct discord_message *p_message);
716 ORCAcode discord_crosspost_message(struct discord *client, const u64_snowflake_t channel_id, const u64_snowflake_t message_id, struct discord_message *p_message);
717 ORCAcode discord_create_reaction(struct discord *client, const u64_snowflake_t channel_id, const u64_snowflake_t message_id, const u64_snowflake_t emoji_id, const char emoji_name[]);
718 ORCAcode discord_delete_own_reaction(struct discord *client, const u64_snowflake_t channel_id, const u64_snowflake_t message_id, const u64_snowflake_t emoji_id, const char emoji_name[]);
719 ORCAcode discord_delete_user_reaction(struct discord *client, const u64_snowflake_t channel_id, const u64_snowflake_t message_id, const u64_snowflake_t user_id, const u64_snowflake_t emoji_id, const char emoji_name[]);
720 ORCAcode discord_get_reactions(struct discord *client, u64_snowflake_t channel_id, u64_snowflake_t message_id, const u64_snowflake_t emoji_id, const char emoji_name[], struct discord_get_reactions_params *params, NTL_T(struct discord_user) *p_users);
721 ORCAcode discord_delete_all_reactions(struct discord *client, u64_snowflake_t channel_id, u64_snowflake_t message_id);
722 ORCAcode discord_delete_all_reactions_for_emoji(struct discord *client, const u64_snowflake_t channel_id, const u64_snowflake_t message_id, const u64_snowflake_t emoji_id, const char emoji_name[]);
723 ORCAcode discord_edit_message(struct discord *client, const u64_snowflake_t channel_id, const u64_snowflake_t message_id, struct discord_edit_message_params *params, struct discord_message *p_message);
724 ORCAcode discord_delete_message(struct discord *client, u64_snowflake_t channel_id, u64_snowflake_t message_id);
725 ORCAcode discord_bulk_delete_messages(struct discord *client, u64_snowflake_t channel_id, NTL_T(u64_snowflake_t) messages);
726 ORCAcode discord_edit_channel_permissions(struct discord *client, const u64_snowflake_t channel_id, const u64_snowflake_t overwrite_id, struct discord_edit_channel_permissions_params *params);
727 ORCAcode discord_get_channel_invites(struct discord *client, const u64_snowflake_t channel_id, NTL_T(struct discord_invite) *p_invites);
728 ORCAcode discord_create_channel_invite(struct discord *client, const u64_snowflake_t channel_id, struct discord_create_channel_invite_params *params, struct discord_invite *p_invite);
729 ORCAcode discord_delete_channel_permission(struct discord *client, const u64_snowflake_t channel_id, const u64_snowflake_t overwrite_id);
730 ORCAcode discord_trigger_typing_indicator(struct discord* client, u64_snowflake_t channel_id);
731 ORCAcode discord_follow_news_channel(struct discord *client, const u64_snowflake_t channel_id, struct discord_follow_news_channel_params *params, struct discord_channel *p_followed_channel);
732 ORCAcode discord_get_pinned_messages(struct discord *client, const u64_snowflake_t channel_id, NTL_T(struct discord_message) *p_messages);
733 ORCAcode discord_pin_message(struct discord *client, const u64_snowflake_t channel_id, const u64_snowflake_t message_id);
734 ORCAcode discord_unpin_message(struct discord *client, const u64_snowflake_t channel_id, const u64_snowflake_t message_id);
735 ORCAcode discord_group_dm_add_recipient(struct discord *client, const u64_snowflake_t channel_id, const u64_snowflake_t user_id, struct discord_group_dm_add_recipient_params *params);
736 ORCAcode discord_group_dm_remove_recipient(struct discord *client, const u64_snowflake_t channel_id, const u64_snowflake_t user_id);
737 ORCAcode discord_start_thread_with_message(struct discord *client, const u64_snowflake_t channel_id, const u64_snowflake_t message_id, struct discord_start_thread_with_message_params *params, struct discord_channel *p_channel);
738 ORCAcode discord_start_thread_without_message(struct discord *client, const u64_snowflake_t channel_id, struct discord_start_thread_without_message_params *params, struct discord_channel *p_channel);
739 ORCAcode discord_join_thread(struct discord *client, const u64_snowflake_t channel_id);
740 ORCAcode discord_add_thread_member(struct discord *client, const u64_snowflake_t channel_id, const u64_snowflake_t user_id);
741 ORCAcode discord_leave_thread(struct discord *client, const u64_snowflake_t channel_id);
742 ORCAcode discord_remove_thread_member(struct discord *client, const u64_snowflake_t channel_id, const u64_snowflake_t user_id);
743 ORCAcode discord_list_thread_members(struct discord *client, const u64_snowflake_t channel_id, NTL_T(struct discord_thread_member) *p_thread_members);
744 ORCAcode discord_list_active_threads(struct discord *client, const u64_snowflake_t channel_id, struct discord_thread_response_body *body);
745 ORCAcode discord_list_public_archived_threads(struct discord *client, const u64_snowflake_t channel_id, const u64_unix_ms_t before, const int limit, struct discord_thread_response_body *body);
746 ORCAcode discord_list_private_archived_threads(struct discord *client, const u64_snowflake_t channel_id, const u64_unix_ms_t before, const int limit, struct discord_thread_response_body *body);
747 ORCAcode discord_list_joined_private_archived_threads(struct discord *client, const u64_snowflake_t channel_id, const u64_unix_ms_t before, const int limit, struct discord_thread_response_body *body);
748 
749 // EMOJI ENDPOINTS
750 ORCAcode discord_list_guild_emojis(struct discord *client, const u64_snowflake_t guild_id, NTL_T(struct discord_emoji) *p_emojis);
751 ORCAcode discord_get_guild_emoji(struct discord *client, const u64_snowflake_t guild_id, const u64_snowflake_t emoji_id, struct discord_emoji *p_emoji);
752 ORCAcode discord_create_guild_emoji(struct discord *client, const u64_snowflake_t guild_id, struct discord_create_guild_emoji_params *params, struct discord_emoji *p_emoji);
753 ORCAcode discord_modify_guild_emoji(struct discord *client, const u64_snowflake_t guild_id, const u64_snowflake_t emoji_id, struct discord_modify_guild_emoji_params *params, struct discord_emoji *p_emoji);
754 ORCAcode discord_delete_guild_emoji(struct discord *client, const u64_snowflake_t guild_id, const u64_snowflake_t emoji_id);
755 
756 // GUILD ENDPOINTS
757 ORCAcode discord_create_guild(struct discord *client, struct discord_create_guild_params *params, struct discord_guild *p_guild);
758 ORCAcode discord_get_guild(struct discord *client, const u64_snowflake_t guild_id, struct discord_guild *p_guild);
759 ORCAcode discord_get_guild_preview(struct discord *client, const u64_snowflake_t guild_id, struct discord_guild_preview *p_guild_preview);
760 ORCAcode discord_modify_guild(struct discord *client, const u64_snowflake_t guild_id, struct discord_modify_guild_params *params, struct discord_guild *p_guild);
761 ORCAcode discord_delete_guild(struct discord *client, const u64_snowflake_t guild_id);
762 ORCAcode discord_get_guild_channels(struct discord *client, const u64_snowflake_t guild_id, NTL_T(struct discord_channel) *p_channels);
763 ORCAcode discord_create_guild_channel(struct discord *client, const u64_snowflake_t guild_id, struct discord_create_guild_channel_params *params, struct discord_channel *p_channel);
764 ORCAcode discord_modify_guild_channel_positions(struct discord *client, const u64_snowflake_t guild_id, NTL_T(struct discord_modify_guild_channel_positions_params) params);
765 ORCAcode discord_get_guild_member(struct discord *client, u64_snowflake_t guild_id, u64_snowflake_t user_id, struct discord_guild_member *p_member);
766 ORCAcode discord_list_guild_members(struct discord *client, const u64_snowflake_t guild_id, struct discord_list_guild_members_params *params, NTL_T(struct discord_guild_member) *p_members);
767 ORCAcode discord_search_guild_members(struct discord *client, const u64_snowflake_t guild_id, struct discord_search_guild_members_params *params, NTL_T(struct discord_guild_member) *p_members);
768 ORCAcode discord_modify_guild_member(struct discord *client, const u64_snowflake_t guild_id, const u64_snowflake_t user_id, struct discord_modify_guild_member_params *params, struct discord_guild_member *p_member);
769 ORCAcode discord_add_guild_member(struct discord *client, const u64_snowflake_t guild_id, const u64_snowflake_t user_id, struct discord_add_guild_member_params *params, struct discord_guild_member *p_member);
770 ORCAcode discord_modify_current_user_nick(struct discord *client, const u64_snowflake_t guild_id, const char nick[]);
771 ORCAcode discord_add_guild_member_role(struct discord *client, const u64_snowflake_t guild_id, const u64_snowflake_t user_id, const u64_snowflake_t role_id);
772 ORCAcode discord_remove_guild_member_role(struct discord *client, const u64_snowflake_t guild_id, const u64_snowflake_t user_id, const u64_snowflake_t role_id);
773 ORCAcode discord_remove_guild_member(struct discord *client, const u64_snowflake_t guild_id, const u64_snowflake_t user_id);
774 ORCAcode discord_get_guild_bans(struct discord *client, const u64_snowflake_t guild_id, NTL_T(struct discord_guild_ban) *p_bans);
775 ORCAcode discord_get_guild_ban(struct discord *client, const u64_snowflake_t guild_id, const u64_snowflake_t user_id, struct discord_guild_ban *p_ban);
776 ORCAcode discord_create_guild_ban(struct discord *client, const u64_snowflake_t guild_id, const u64_snowflake_t user_id, int delete_message_days, const char reason[]);
777 ORCAcode discord_remove_guild_ban(struct discord *client, const u64_snowflake_t guild_id, const u64_snowflake_t user_id, const char reason[]);
778 ORCAcode discord_get_guild_roles(struct discord *client, const u64_snowflake_t guild_id, NTL_T(struct discord_permissions_role) *p_roles);
779 ORCAcode discord_create_guild_role(struct discord *client, const u64_snowflake_t guild_id, struct discord_create_guild_role_params *params, struct discord_permissions_role *p_role);
780 ORCAcode discord_modify_guild_role_positions(struct discord *client, const u64_snowflake_t guild_id, NTL_T(struct discord_modify_guild_role_positions_params) params, NTL_T(struct discord_permissions_role) *p_roles);
781 ORCAcode discord_modify_guild_role(struct discord *client, const u64_snowflake_t guild_id, const u64_snowflake_t role_id, struct discord_modify_guild_role_params *params, struct discord_permissions_role *p_role);
782 ORCAcode discord_delete_guild_role(struct discord *client, const u64_snowflake_t guild_id, const u64_snowflake_t role_id);
783 
784 // INVITE ENDPOINTS
785 ORCAcode discord_get_invite(struct discord *client, char *invite_code, struct discord_get_invite_params *params, struct discord_invite *p_invite);
786 ORCAcode discord_delete_invite(struct discord *client, char *invite_code, struct discord_invite *p_invite);
787 
788 // USER ENDPOINTS
789 ORCAcode discord_get_user(struct discord *client, const u64_snowflake_t user_id, struct discord_user *p_user);
790 ORCAcode discord_modify_current_user(struct discord *client, struct discord_modify_current_user_params *params, struct discord_user *p_user);
791 ORCAcode discord_get_current_user(struct discord *client, struct discord_user *p_user);
792 ORCAcode sb_discord_get_current_user(struct discord *client, struct sized_buffer *p_sb_user);
793 ORCAcode discord_get_current_user_guilds(struct discord *client, NTL_T(struct discord_guild) *p_guilds);
794 ORCAcode discord_leave_guild(struct discord *client, const u64_snowflake_t guild_id);
795 ORCAcode discord_create_dm(struct discord *client, const u64_snowflake_t recipient_id, struct discord_channel *p_dm_channel);
796 ORCAcode discord_create_group_dm(struct discord *client, struct discord_create_group_dm_params *params, struct discord_channel *p_dm_channel);
797 ORCAcode discord_get_user_connections(struct discord *client, NTL_T(struct discord_connection) *p_connections);
798 
799 // VOICE ENDPOINTS
800 ORCAcode discord_list_voice_regions(struct discord *client, NTL_T(struct discord_voice_region) *p_voice_regions);
801 
802 // GATEWAY ENDPOINTS
803 ORCAcode discord_get_gateway(struct discord *client, struct discord_session *p_session);
804 ORCAcode discord_get_gateway_bot(struct discord *client, struct discord_session *p_session);
805 
806 
807 /* * * * * * * * * * * * * * * * * * * */
808 /* * * * MISCELLANEOUS FUNCTIONS * * * */
809 
810 // EMBED MISC
811 void discord_embed_set_thumbnail(struct discord_embed *embed, char url[], char proxy_url[], int height, int width);
812 void discord_embed_set_image(struct discord_embed *embed, char url[], char proxy_url[], int height, int width);
813 void discord_embed_set_video(struct discord_embed *embed, char url[], char proxy_url[], int height, int width);
814 void discord_embed_set_footer(struct discord_embed *embed, char text[], char icon_url[], char proxy_icon_url[]);
815 void discord_embed_set_provider(struct discord_embed *embed, char name[], char url[]);
816 void discord_embed_set_author(struct discord_embed *embed, char name[], char url[], char icon_url[], char proxy_icon_url[]);
817 void discord_embed_add_field(struct discord_embed *embed, char name[], char value[], bool Inline);
818 
819 // CHANNEL MISC
820 void discord_overwrite_append(NTL_T(struct discord_channel_overwrite) *permission_overwrites, u64_snowflake_t id, int type, enum discord_permissions_bitwise_flags allow, enum discord_permissions_bitwise_flags deny);
821 ORCAcode discord_get_channel_at_pos(struct discord *client, const u64_snowflake_t guild_id, const enum discord_channel_types type, const size_t position, struct discord_channel *p_channel);
822 ORCAcode discord_delete_messages_by_author_id(struct discord *client, u64_snowflake_t channel_id, u64_snowflake_t author_id);
823 
824 // GUILD MISC
825 ORCAcode discord_disconnect_guild_member(struct discord *client, const u64_snowflake_t guild_id, const u64_snowflake_t user_id, struct discord_guild_member *p_member);
826 
827 
828 #ifdef _DISCORD_ADD_ONS
830 #endif
831 
832 #endif // DISCORD_H
discord_edit_channel_permissions_params
Edit Channel Permissions.
Definition: channel.endpoints-params.h:173
discord_global_init
void discord_global_init()
Initialize resources of globals used by discord.h.
discord_create_message_params::tts
bool tts
enable/disable text-to-speech
Definition: discord.h:318
voice_state_update_cb
void(* voice_state_update_cb)(struct discord *client, const struct discord_user *bot, const struct discord_voice_state *voice_state)
Voice State Update callback.
Definition: discord.h:263
discord_add_intents
void discord_add_intents(struct discord *client, enum discord_gateway_intents code)
Subscribe to Discord Gateway events.
discord::data
void * data
space for user arbitrary data
Definition: discord-internal.h:282
discord_connection
Connection Structure.
Definition: user.h:148
discord_replace_presence
void discord_replace_presence(struct discord *client, struct discord_gateway_status_update *presence)
Replace the Client presence with a struct discord_gateway_status_update.
discord_set_on_ready
void discord_set_on_ready(struct discord *client, idle_cb callback)
Set a callback that triggers when the client is ready.
discord_session::identify_tstamp
u64_unix_ms_t identify_tstamp
timestamp of last succesful identify request
Definition: discord.h:292
discord_config_init
struct discord * discord_config_init(const char config_file[])
Create a Discord Client handle by a bot.config file.
discord_create_guild_role_params
Create Guild Role.
Definition: guild.endpoints-params.h:535
discord_modify_guild_role_positions_params
Modify Guild Role Positions.
Definition: guild.endpoints-params.h:597
discord_modify_channel_params
Modify Channel.
Definition: channel.endpoints-params.h:17
discord_list_guild_members_params
Definition: discord.h:348
discord_set_on_guild_role_update
void discord_set_on_guild_role_update(struct discord *client, guild_role_cb callback)
Set a callback that triggers when a guild role is updated.
channel_cb
void(* channel_cb)(struct discord *client, const struct discord_user *bot, const struct discord_channel *channel)
Channel Create/Update/Delete callback.
Definition: discord.h:196
discord_set_on_message_create
void discord_set_on_message_create(struct discord *client, message_cb callback)
Set a callback that triggers when a message is created.
idle_cb
void(* idle_cb)(struct discord *client, const struct discord_user *bot)
Idle callback.
Definition: discord.h:78
discord_set_on_message_reaction_remove
void discord_set_on_message_reaction_remove(struct discord *client, message_reaction_remove_cb callback)
Set a callback that triggers when a message reaction is removed.
discord_permissions_role
Role Structure.
Definition: permissions.h:56
discord_guild_ban
Ban Structure.
Definition: guild.h:820
discord_set_on_guild_role_create
void discord_set_on_guild_role_create(struct discord *client, guild_role_cb callback)
Set a callback that triggers when a guild role is created.
discord_modify_current_user_params
Modify Current User.
Definition: user.endpoints-params.h:17
discord_gateway_status_update
Gateway Status Update Structure.
Definition: gateway.h:194
discord_channel_allowed_mentions
Allowed Mentions Structure.
Definition: channel.h:1024
discord_set_presence
void discord_set_presence(struct discord *client, struct discord_gateway_activity *activity, char status[], bool afk)
Modify the Client presence state.
discord_session
Definition: discord.h:282
message_reaction_remove_emoji_cb
void(* message_reaction_remove_emoji_cb)(struct discord *client, const struct discord_user *bot, const u64_snowflake_t channel_id, const u64_snowflake_t message_id, const u64_snowflake_t guild_id, const struct discord_emoji *emoji)
Message Reaction Remove Emoji callback.
Definition: discord.h:251
discord_create_message_params::nonce
char * nonce
the nonce of the message being sent
Definition: discord.h:317
discord_voice_state
Voice State Structure.
Definition: voice.h:17
discord_set_on_idle
void discord_set_on_idle(struct discord *client, idle_cb callback)
Set a callback that triggers at every event-loop iteration.
discord_set_on_voice_state_update
void discord_set_on_voice_state_update(struct discord *client, voice_state_update_cb callback)
Set a callback that triggers when a voice state is updated.
discord_set_on_message_reaction_remove_emoji
void discord_set_on_message_reaction_remove_emoji(struct discord *client, message_reaction_remove_emoji_cb callback)
Set a callback that triggers when all instances of a particular reaction from some message is removed...
discord_set_on_guild_ban_remove
void discord_set_on_guild_ban_remove(struct discord *client, guild_ban_cb callback)
Set a callback that triggers when a guild ban is removed.
discord_set_data
void * discord_set_data(struct discord *client, void *data)
Keep some user arbitrary data, by associating it to the client.
discord_session::shards
int shards
The recommended number of shards to use when connecting.
Definition: discord.h:284
discord_session::reset_after
int reset_after
the number of milliseconds after which the limit resets
Definition: discord.h:288
discord_set_on_voice_server_update
void discord_set_on_voice_server_update(struct discord *client, voice_server_update_cb callback)
Set a callback that triggers when a voice server is updated.
event_raw_cb
void(* event_raw_cb)(struct discord *client, enum discord_gateway_events event, struct sized_buffer *sb_bot, struct sized_buffer *event_data)
Raw Event callback.
Definition: discord.h:87
discord_set_on_guild_member_add
void discord_set_on_guild_member_add(struct discord *client, guild_member_cb callback)
Set a callback that triggers when a guild member is added.
discord_init
struct discord * discord_init(const char token[])
Create a Discord Client handle by its token.
discord_set_on_message_reaction_add
void discord_set_on_message_reaction_add(struct discord *client, message_reaction_add_cb callback)
Set a callback that triggers when a message reaction is added.
discord_follow_news_channel_params
Follow News Channel.
Definition: channel.endpoints-params.h:227
discord_create_message_params::size
size_t size
the size of the file being sent (if content is set)
Definition: discord.h:330
discord_global_cleanup
void discord_global_cleanup()
Free resources of globals used by discord.h.
guild_member_cb
void(* guild_member_cb)(struct discord *client, const struct discord_user *bot, const u64_snowflake_t guild_id, const struct discord_guild_member *member)
Guild Member Add/Update callback.
Definition: discord.h:122
discord::token
struct sized_buffer token
the bot token
Definition: discord-internal.h:272
discord_session::event_tstamp
u64_unix_ms_t event_tstamp
timestamp of last succesful event timestamp in ms (resets every 60s)
Definition: discord.h:294
discord_session::url
char url[1024]
The WSS URL that can be used for connecting to the gateway.
Definition: discord.h:283
discord_group_dm_add_recipient_params
Group DM Add Recipient.
Definition: channel.endpoints-params.h:343
discord_set_on_message_update
void discord_set_on_message_update(struct discord *client, message_cb callback)
Set a callback that triggers when a message is updated.
message_reaction_remove_cb
void(* message_reaction_remove_cb)(struct discord *client, const struct discord_user *bot, const u64_snowflake_t user_id, const u64_snowflake_t channel_id, const u64_snowflake_t message_id, const u64_snowflake_t guild_id, const struct discord_emoji *emoji)
Message Reaction Remove callback.
Definition: discord.h:229
discord_set_on_guild_member_update
void discord_set_on_guild_member_update(struct discord *client, guild_member_cb callback)
Set a callback that triggers when a guild member is updated.
message_delete_cb
void(* message_delete_cb)(struct discord *client, const struct discord_user *bot, const u64_snowflake_t id, const u64_snowflake_t channel_id, const u64_snowflake_t guild_id)
Message Delete callback.
Definition: discord.h:171
discord_create_message_params
Definition: discord.h:314
EVENT_WILL_BE_HANDLED_IN_CHILD_THREAD
@ EVENT_WILL_BE_HANDLED_IN_CHILD_THREAD
handle this event in a child thread
Definition: discord.h:647
discord_guild_preview
Guild Preview Object.
Definition: guild.h:383
discord_guild
Guild Structure.
Definition: guild.h:17
discord_channel_overwrite
Overwrite Structure.
Definition: channel.h:716
discord_gateway_activity
Activity Structure.
Definition: gateway.h:308
discord_get_reactions_params
Get Reactions.
Definition: channel.endpoints-params.h:123
discord_audit_log
Audit Log Structure.
Definition: audit_log.h:17
discord_get_data
void * discord_get_data(struct discord *client)
Received user arbitrary data associated to the client.
discord_modify_guild_role_params
Modify Guild Role.
Definition: guild.endpoints-params.h:647
discord_set_on_message_reaction_remove_all
void discord_set_on_message_reaction_remove_all(struct discord *client, message_reaction_remove_all_cb callback)
Set a callback that triggers when all reaction from some message is removed.
discord_set_on_guild_role_delete
void discord_set_on_guild_role_delete(struct discord *client, guild_role_delete_cb callback)
Set a callback that triggers when a guild role is deleted.
discord_set_on_command
void discord_set_on_command(struct discord *client, char *command, message_cb callback)
Set command/callback pair, the callback is triggered if someone types command in chat.
message_cb
void(* message_cb)(struct discord *client, const struct discord_user *bot, const struct discord_message *message)
Message Create/Update callback.
Definition: discord.h:156
discord_voice_region
Voice Region Structure.
Definition: voice.h:107
guild_role_delete_cb
void(* guild_role_delete_cb)(struct discord *client, const struct discord_user *bot, const u64_snowflake_t guild_id, const u64_snowflake_t role_id)
Guild Role Delete callback.
Definition: discord.h:110
discord_thread_member
Thread Member Object.
Definition: channel.h:838
discord_list_guild_members_params::after
u64_snowflake_t after
the highest user id in the previous page
Definition: discord.h:350
discord_session::total
int total
the total number of session starts the current user is allowed
Definition: discord.h:286
discord_create_message_params::content
char * content
the content of the message being sent
Definition: discord.h:316
discord_event_handling_mode
discord_event_handling_mode
Definition: discord.h:644
discord_run
void discord_run(struct discord *client)
Start a connection to the Discord Gateway.
discord_set_on_channel_delete
void discord_set_on_channel_delete(struct discord *client, channel_cb callback)
Set a callback that triggers when a channel is deleted.
discord_set_on_guild_ban_add
void discord_set_on_guild_ban_add(struct discord *client, guild_ban_cb callback)
Set a callback that triggers when a guild ban is added.
discord_search_guild_members_params
Search Guild Members.
Definition: guild.endpoints-params.h:361
discord_edit_message_params
Definition: discord.h:338
discord_remove_intents
void discord_remove_intents(struct discord *client, enum discord_gateway_intents code)
Unsubscribe from Discord Gateway events.
guild_role_cb
void(* guild_role_cb)(struct discord *client, const struct discord_user *bot, const u64_snowflake_t guild_id, const struct discord_permissions_role *role)
Guild Role Create/Update callback.
Definition: discord.h:100
EVENT_IS_HANDLED
@ EVENT_IS_HANDLED
this event has been handled
Definition: discord.h:645
discord_voice_cbs
Definition: discord-voice-connections.h:69
discord_message_reference
Message Reference Structure.
Definition: channel.h:259
u64_unix_ms_t
uint64_t u64_unix_ms_t
unix time in ms
Definition: discord.h:26
discord_session::max_concurrency
int max_concurrency
the number of identify requests allowed per 5 seconds
Definition: discord.h:289
discord
The Discord Client structure.
Definition: discord-internal.h:271
discord_set_on_channel_create
void discord_set_on_channel_create(struct discord *client, channel_cb callback)
Set a callback that triggers when a channel is created.
guild_ban_cb
void(* guild_ban_cb)(struct discord *client, const struct discord_user *bot, const u64_snowflake_t guild_id, const struct discord_user *user)
Guild Ban Add/Remove callback.
Definition: discord.h:144
discord_create_guild_emoji_params
Create Guild Emoji.
Definition: emoji.endpoints-params.h:17
u64_snowflake_t
uint64_t u64_snowflake_t
snowflake datatype
Definition: discord.h:32
discord_get_invite_params
Get Invite.
Definition: invite.endpoints-params.h:17
discord_session::concurrent
int concurrent
active concurrent sessions
Definition: discord.h:291
discord_session::remaining
int remaining
the remaining number of session starts the current user is allowed
Definition: discord.h:287
discord_set_prefix
void discord_set_prefix(struct discord *client, char *prefix)
Set a mandatory prefix before commands.
discord_create_channel_invite_params
Create Channel Invite.
Definition: channel.endpoints-params.h:273
discord_thread_response_body
List Active Threads.
Definition: channel.endpoints-params.h:493
discord_message
Message Structure.
Definition: channel.h:465
discord_create_group_dm_params
Create Group DM.
Definition: user.endpoints-params.h:67
voice_server_update_cb
void(* voice_server_update_cb)(struct discord *client, const struct discord_user *bot, const char *token, const u64_snowflake_t guild_id, const char *endpoint)
Voice Server Update callback.
Definition: discord.h:271
discord_session::event_count
int event_count
event counter to avoid reaching limit of 120 events per 60 sec
Definition: discord.h:296
discord_start_thread_without_message_params
Start Thread without Message.
Definition: channel.endpoints-params.h:443
message_reaction_add_cb
void(* message_reaction_add_cb)(struct discord *client, const struct discord_user *bot, const u64_snowflake_t user_id, const u64_snowflake_t channel_id, const u64_snowflake_t message_id, const u64_snowflake_t guild_id, const struct discord_guild_member *member, const struct discord_emoji *emoji)
Message Reaction Add callback.
Definition: discord.h:216
discord_guild_member
Guild Member Structure.
Definition: guild.h:515
guild_member_remove_cb
void(* guild_member_remove_cb)(struct discord *client, const struct discord_user *bot, const u64_snowflake_t guild_id, const struct discord_user *user)
Guild Member Remove callback.
Definition: discord.h:132
discord_modify_guild_member_params
Modify Guild Member.
Definition: guild.endpoints-params.h:473
discord_channel
Channel Structure.
Definition: channel.h:31
discord_modify_guild_emoji_params
Modify Guild Emoji.
Definition: emoji.endpoints-params.h:71
discord_emoji
Emoji Structure.
Definition: emoji.h:17
discord-voice-connections.h
File containing internal functions and datatypes for Voice Connections.
discord_set_on_guild_member_remove
void discord_set_on_guild_member_remove(struct discord *client, guild_member_remove_cb callback)
Set a callback that triggers when a guild member is removed.
discord_invite
Invite Structure.
Definition: invite.h:25
discord_start_thread_with_message_params
Start Thread with Message.
Definition: channel.endpoints-params.h:393
discord_create_guild_channel_params
Create Guild Channel.
Definition: guild.endpoints-params.h:221
discord_set_voice_cbs
void discord_set_voice_cbs(struct discord *client, struct discord_voice_cbs *callbacks)
Helper to quickly set voice callbacks.
discord_add_guild_member_params
Add Guild Member.
Definition: guild.endpoints-params.h:411
discord_modify_guild_channel_positions_params
Modify Guild Channel Positions.
Definition: guild.endpoints-params.h:303
discord_set_on_channel_pins_update
void discord_set_on_channel_pins_update(struct discord *client, channel_pins_update_cb callback)
Set a callback that triggers when some channel pins are updated.
discord_user
User Structure.
Definition: user.h:45
discord_create_message_params::name
char * name
the name of the file being sent
Definition: discord.h:328
message_reaction_remove_all_cb
void(* message_reaction_remove_all_cb)(struct discord *client, const struct discord_user *bot, const u64_snowflake_t channel_id, const u64_snowflake_t message_id, const u64_snowflake_t guild_id)
Message Reaction Remove All callback.
Definition: discord.h:241
EVENT_WILL_BE_HANDLED_IN_MAIN_THREAD
@ EVENT_WILL_BE_HANDLED_IN_MAIN_THREAD
handle this event in main thread
Definition: discord.h:646
discord_get_guild_audit_log_params
Definition: audit_log.endpoints-params.h:15
discord_get_channel_messages_params
Definition: discord.h:302
discord_set_on_channel_update
void discord_set_on_channel_update(struct discord *client, channel_cb callback)
Set a callback that triggers when a channel is updated.
discord_list_guild_members_params::limit
int limit
the number of members to return (1-1000)
Definition: discord.h:349
discord_create_guild_params
Create Guild.
Definition: guild.endpoints-params.h:17
discord_cleanup
void discord_cleanup(struct discord *client)
Free a Discord Client handle.
message_delete_bulk_cb
void(* message_delete_bulk_cb)(struct discord *client, const struct discord_user *bot, const ja_u64 **ids, const u64_snowflake_t channel_id, const u64_snowflake_t guild_id)
Message Delete Bulk callback.
Definition: discord.h:182
discord_embed
Embed Structure.
Definition: channel.h:1082
channel_pins_update_cb
void(* channel_pins_update_cb)(struct discord *client, const struct discord_user *bot, const u64_snowflake_t guild_id, const u64_snowflake_t channel_id, const u64_unix_ms_t last_pin_timestamp)
Channel Pins Update callback.
Definition: discord.h:205
discord_set_on_event_raw
void discord_set_on_event_raw(struct discord *client, event_raw_cb callback)
Set a callback that triggers on any event the client is subscribed to.
discord_set_on_message_delete
void discord_set_on_message_delete(struct discord *client, message_delete_cb callback)
Set a callback that triggers when a message is deleted.
discord_modify_guild_params
Modify Guild.
Definition: guild.endpoints-params.h:103