{"id":13409634,"url":"https://github.com/Cogmasters/concord","last_synced_at":"2025-03-14T15:30:20.324Z","repository":{"id":37794460,"uuid":"445037897","full_name":"Cogmasters/concord","owner":"Cogmasters","description":"A Discord API wrapper library made in C","archived":false,"fork":false,"pushed_at":"2024-09-13T19:49:02.000Z","size":37617,"stargazers_count":516,"open_issues_count":30,"forks_count":29,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-09-14T10:42:08.988Z","etag":null,"topics":["api-client","api-rest","api-wrapper","bsd","c","discord","discord-api","discord-bot","discord-library","linux","websockets","windows"],"latest_commit_sha":null,"homepage":"https://cogmasters.github.io/concord/","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Cogmasters.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"docs/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-06T04:18:04.000Z","updated_at":"2024-09-14T04:35:43.000Z","dependencies_parsed_at":"2024-01-03T01:20:05.404Z","dependency_job_id":"50a616fc-e893-4db7-9d37-a75b796ceb27","html_url":"https://github.com/Cogmasters/concord","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cogmasters%2Fconcord","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cogmasters%2Fconcord/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cogmasters%2Fconcord/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cogmasters%2Fconcord/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Cogmasters","download_url":"https://codeload.github.com/Cogmasters/concord/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243600427,"owners_count":20317274,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-client","api-rest","api-wrapper","bsd","c","discord","discord-api","discord-bot","discord-library","linux","websockets","windows"],"created_at":"2024-07-30T20:01:02.456Z","updated_at":"2025-03-14T15:30:19.868Z","avatar_url":"https://github.com/Cogmasters.png","language":"C","readme":"[migrating-shield]: https://img.shields.io/badge/Gist-Migrating%20from%20v1-yellow\n[migrating-link]: https://gist.github.com/lcsmuller/d6aee306bac229a7873f5c243bf7858b\n[migrating-orca-link]: https://gist.github.com/lcsmuller/b5137e66d534a57e0075f9d838c9170e\n[discord-shield]: https://img.shields.io/discord/928763123362578552?color=5865F2\u0026logo=discord\u0026logoColor=white\n[discord-invite]: https://discord.gg/Y7Xa6MA82v\n[discord-config-init]: https://cogmasters.github.io/concord/group__DiscordClient.html#ga75bbe1d3eb9e6d03953b6313e5543afb\n[discord-config-get-field]: https://cogmasters.github.io/concord/group__DiscordClient.html#gac4486003ffab83de397c0bebb74b3307\n\n\u003cdiv align=\"center\"\u003e\n\u003cimg src=\"https://raw.githubusercontent.com/Cogmasters/concord/bd1436a84af21384d93d92aed32b4c7828d0d793/docs/static/logo.svg\" width=\"250\" alt=\"Concord Logo\"\u003e\n\u003c/div\u003e\n\n# Concord - C Discord API library\n\n[ ![discord-shield][] ][discord-invite]\n[ ![migrating-shield][] ][migrating-link]\n\n## 🚨 Concord is not dead! 🚨\nDevelopment has been happening in the dev branch. We are working on new features and improvements. To access the latest version of the library, please check out the dev branch.\n\n## About\n\nConcord is an asynchronous C99 Discord API library with minimal external dependencies, and a low-level translation of the Discord official documentation to C code.\n\n### Examples\n\n*The following are minimalistic examples, refer to [`examples/`](examples/) for a better overview.*\n\n#### Slash Commands (new method)\n\n*Note: you need to replace `GUILD_ID` with an actual guild ID, or this example won't compile!*\nYou can use a macro to do this: `#define GUILD_ID 1234567898765431`\n\n```c\n#include \u003cstring.h\u003e\n#include \u003cconcord/discord.h\u003e\n\nvoid on_ready(struct discord *client, const struct discord_ready *event) {\n    struct discord_create_guild_application_command params = {\n        .name = \"ping\",\n        .description = \"Ping command!\"\n    };\n    discord_create_guild_application_command(client, event-\u003eapplication-\u003eid,\n                                             GUILD_ID, \u0026params, NULL);\n}\n\nvoid on_interaction(struct discord *client, const struct discord_interaction *event) {\n    if (event-\u003etype != DISCORD_INTERACTION_APPLICATION_COMMAND)\n        return; /* return if interaction isn't a slash command */\n\n    if (strcmp(event-\u003edata-\u003ename, \"ping\") == 0) {\n          struct discord_interaction_response params = {\n                .type = DISCORD_INTERACTION_CHANNEL_MESSAGE_WITH_SOURCE,\n                .data = \u0026(struct discord_interaction_callback_data){\n                      .content = \"pong\"\n                }\n          };\n          discord_create_interaction_response(client, event-\u003eid,\n                                              event-\u003etoken, \u0026params, NULL);\n    }\n}\n\nint main(void) {\n    struct discord *client = discord_init(BOT_TOKEN);\n    discord_set_on_ready(client, \u0026on_ready);\n    discord_set_on_interaction_create(client, \u0026on_interaction);\n    discord_run(client);\n}\n```\n\n#### Message Commands (old method)\n\n```c\n#include \u003cstring.h\u003e\n#include \u003cconcord/discord.h\u003e\n#include \u003cconcord/log.h\u003e\n\nvoid on_ready(struct discord *client, const struct discord_ready *event) {\n    log_info(\"Logged in as %s!\", event-\u003euser-\u003eusername);\n}\n\nvoid on_message(struct discord *client, const struct discord_message *event) {\n    if (strcmp(event-\u003econtent, \"ping\") == 0) {\n        struct discord_create_message params = { .content = \"pong\" };\n        discord_create_message(client, event-\u003echannel_id, \u0026params, NULL);\n    }\n}\n\nint main(void) {\n    struct discord *client = discord_init(BOT_TOKEN);\n    discord_add_intents(client, DISCORD_GATEWAY_MESSAGE_CONTENT);\n    discord_set_on_ready(client, \u0026on_ready);\n    discord_set_on_message_create(client, \u0026on_message);\n    discord_run(client);\n}\n```\n\n## Supported operating systems (minimum requirements)\n\n* GNU/Linux 4.x\n* FreeBSD 12\n* NetBSD 8.1\n* Windows 7 (Cygwin)\n* GNU/Hurd 0.9\n* Mac OS X 10.9\n\n*Note: big-endian processors running certain OSes like SPARC Solaris, PowerPC AIX, System Z z/OS or Linux, or MIPS IRIX are NOT supported. There are currently a few issues that prevent some of the logic from correctly on big-endian systems. This will be fixed soon.*\n\n## Build Instructions\n\nThe only dependency is `curl-7.56.1` or higher. If you are compiling libcurl from source, you will need to build it with SSL support.\n\n### On Windows\n\n* Install **Cygwin**\n* **Make sure that you installed libcurl, gcc, make, and git when you ran the Cygwin installer!**\n* You will want to check the Windows tutorial [here](docs/guides/compiling_on_windows.md)!\n* Mingw64 and Msys2 are currently NOT supported. Please see [this](docs/guides/msys2_and_mingw64.md) for more information.\n* Once installed, compile it normally like you would on UNIX/Linux/OS X/BSD.\n* Note: you will likely need to include `-L/usr/local/lib -I/usr/local/include` on your `gcc` command, or in your `CFLAGS` variable in your Makefile for your bot.\n\n### On Linux, BSD, and Mac OS X\n\n*(note -- `#` means that you should be running as root)*\n\n#### Ubuntu and Debian\n\n```console\n# apt update \u0026\u0026 apt install -y libcurl4-openssl-dev\n```\n\n#### Void Linux\n\n```console\n# xbps-install -S libcurl-devel\n```\n\n#### Alpine\n\n```console\n# apk add curl-dev\n```\n\n#### FreeBSD\n\n```console\n# pkg install curl\n```\n\n#### OS X\n* Note: you will need to install Xcode, or at a minimum, the command-line tools with `xcode-select --install`.\n```console\n$ brew install curl (Homebrew)\n$ port install curl (MacPorts)\n```\n\n#### Arch Linux / Manjaro (Arch based)\n\n```console\ngit clone https://aur.archlinux.org/concord-git.git\ncd concord-git\nmakepkg -Acs\npacman -U concord-git-version-any.pkg.tar.zst\n```\n\nAlternatively, you can use an AUR helper:\n\n```console\nyay -S concord-git\n```\n\n## Setting up your environment\n\n### Clone Concord into your workspace\n\n```console\n$ git clone https://github.com/cogmasters/concord.git \u0026\u0026 cd concord\n```\n\n### Compile Concord\n\n```console\n$ make\n```\n\n### Special notes for non-Linux systems\n\nYou might run into trouble with the compiler and linker not finding your Libcurl headers. You can do something like this:\n```console\n$ CFLAGS=-I\u003csome_path\u003e LDFLAGS=-L\u003csome_path\u003e make\n```\nFor instance, on a FreeBSD system:\n```console\n$ CFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib make\n```\nOn OS X using MacPorts:\n```console\n$ CFLAGS=-I/opt/local/include LDFLAGS=-L/opt/local/lib make\n```\nOn OS X using a self-compiled libcurl:\n```console\n$ CFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/include make\n```\nOn Windows with Cygwin, you might need to pass both arguments to use POSIX threading:\n```console\n$ CFLAGS=\"-pthread -lpthread\" make\n```\n\n### Special note about linking Concord against another library\nIn some cases, you might want to link Concord into a shared object, or link it as a shared object into another shared\nobject. In that case, you will need to compile Concord with `CFLAGS=\"-fpic\" make`. \n\n## Configuring Concord\n\n[discord\\_config\\_init()][discord-config-init] is the initialization method that allows configuring your bot without recompiling.\n\nThe following outlines `config.json` fields:\n```js\n{\n  \"logging\": { // logging directives\n    \"level\": \"trace\",        // trace, debug, info, warn, error, fatal\n    \"filename\": \"bot.log\",   // the log output file\n    \"quiet\": false,          // change to true to disable logs in console\n    \"overwrite\": true,       // overwrite file if already exists, append otherwise\n    \"use_color\": true,       // display color for log entries\n    \"http\": {\n      \"enable\": true,        // generate http specific logging\n      \"filename\": \"http.log\" // the HTTP log output file\n    },\n    \"disable_modules\": [\"WEBSOCKETS\", \"USER_AGENT\"] // disable logging for these modules\n  },\n  \"discord\": { // discord directives\n    \"token\": \"YOUR-BOT-TOKEN\",         // replace with your bot token\n    \"default_prefix\": {                 \n      \"enable\": false,                 // enable default command prefix\n      \"prefix\": \"YOUR-COMMANDS-PREFIX\" // replace with your prefix\n    }\n  },\n  ... // here you can add your custom fields *\n}\n```\n\\* *Your custom field contents can be fetched with [discord\\_config\\_get\\_field()][discord-config-get-field]*\n\n## Test Copycat-Bot\n\n1. Get your bot token and add it to `config.json`, \n   by assigning it to discord's \"token\" field. There are \n   well written instructions from \n   [discord-irc](https://github.com/reactiflux/discord-irc/wiki/Creating-a-discord-bot-\u0026-getting-a-token)\n   explaining how to get your bot token and adding it to a server.\n2. Build example executables:\n   ```console\n   $ make examples\n   ```\n3. Run Copycat-Bot:\n   ```console\n   $ cd examples \u0026\u0026 ./copycat\n   ```\n\n### Get Copycat-Bot Response\n\nType a message in any channel the bot is part of and the bot should send an exact copy of it in return.\n\n### Terminate Copycat-Bot\n\nWith \u003ckbd\u003eCtrl\u003c/kbd\u003e+\u003ckbd\u003ec\u003c/kbd\u003e or with \u003ckbd\u003eCtrl\u003c/kbd\u003e+\u003ckbd\u003e|\u003c/kbd\u003e\n\n## Configure your build\n\nThe following outlines special flags and targets to override the default Makefile build with additional functionalities.\n\n### Special compilation flags\n\n* `-DCCORD_SIGINTCATCH`\n    * By default Concord will not shutdown gracefully when a SIGINT is received (i.e. \u003ckbd\u003eCtrl\u003c/kbd\u003e+\u003ckbd\u003ec\u003c/kbd\u003e), enable this flag if you wish it to be handled for you.\n* `-DCCORD_DEBUG_WEBSOCKETS`\n    * Enable verbose debugging for WebSockets communication.\n* `-DCCORD_DEBUG_HTTP`\n    * Enable verbose debugging for HTTP communication.\n\n*Example:*\n```console\n$ CFLAGS=\"-DCCORD_SIGINTCATCH -DCCORD_DEBUG_HTTP\" make\n```\n\n### Special targets\n\n* `make shared`\n    * Produce a dynamically-linked version of Concord. This Makefile is intended for GNU-style compilers, such as `gcc` or `clang`.\n* `make shared_osx`\n    * Produce a dynamically-linked version of Concord, for OS X and Darwin systems. \n* `make voice`\n    * Enable experimental Voice Connection handling - not production ready.\n* `make debug`\n    * Enable some flags useful while developing, such as `-O0` and `-g`\n\n## Installing Concord\n\n*(note -- `#` means that you should be running as root)*\n\n```console\n# make install\n```\n\nThis will install the headers and library files into $PREFIX. You can override this as such:\n```console\n# PREFIX=/opt/concord make install\n```\n\n### Cross-compiling Concord\nTo cross-compile Concord, see the manual [here](docs/guides/cross_compiling.md).\n\n### Included dependencies\n\nThe following are `stable` and well documented dependencies that are packaged with Concord and can be included to your projects:\n\n| File                                                  | Description                                        |\n|-------------------------------------------------------|----------------------------------------------------|\n| [cog-utils](https://github.com/Cogmasters/cog-utils)  | General purpose functions aimed at portability     |\n| [log.c](https://github.com/rxi/log.c)\\*               | A simple C99 logging library                       |\n| [carray](https://github.com/c-ware/carray)\\*          | Macro-based implementation of type-safe arrays     |\n| [anomap](https://github.com/Anotra/anomap)\\*          | Sorted key/value storage for C99                   |\n| [chash](https://github.com/c-ware/chash)\\*            | Macro-based implementation of type-safe hashtables |\n| [json-build](https://github.com/lcsmuller/json-build) | Tiny, zero-allocation JSON serializer              |\n| [jsmn-find](https://github.com/lcsmuller/jsmn-find)   | Tiny, zero-allocation JSON tokenizer               |\n\n\\* *Concord uses its own modified version that may be not up to date with the original*\n\nNote that included headers must be `concord/` prefixed:\n```c\n#include \u003cconcord/discord.h\u003e\n#include \u003cconcord/log.h\u003e\n```\n\n### Standalone executable\n\n#### GCC \n\n```console\n$ gcc myBot.c -o myBot -pthread -ldiscord -lcurl\n```\n\n#### Clang\n\n```console\n$ clang myBot.c -o myBot -pthread -ldiscord -lcurl\n```\n\n#### UNIX C compilers\n##### This includes the following compilers:\n\n* IBM XL C/C++ (AIX, z/OS, IBM i)\n* Sun/Oracle Studio (Solaris)\n* IRIX MIPSpro C++ (IRIX) -- NOTE: currently not supported\n* HP aCC (HP-UX)\n* Compaq C (Tru64 UNIX) -- NOTE: also currently not supported\n*Note: if you want to actually compile this on one of the systems listed above, please see the \"Compiling on old computers\" guide.*\n\n```console\n$ cc myBot.c -o myBot -ldiscord -lcurl -lpthread\n```\n\nNote: some systems such as **Cygwin** require you to do this:\n```console\n$ gcc myBot.c -o myBot -pthread -lpthread -ldiscord -lcurl\n```\n(this links against libpthread.a in `/usr/lib`)\n\n## Recommended debuggers\n\nFirst, make sure your executable is compiled with the `-g` flag to ensure human-readable debugger messages.\n\n### Valgrind\n\nUsing valgrind to check for memory leaks:\n\n```console\nvalgrind --leak-check=full ./myBot\n```\nFor a more comprehensive guide check [Valgrind's Quick Start](https://valgrind.org/docs/manual/quick-start.html).\n\n### GDB\n\nUsing GDB to check for runtime errors, such as segmentation faults:\n\n```console\n$ gdb ./myBot\n```\nAnd then execute your bot from the gdb environment:\n```console\n(gdb) run\n```\nIf the program has crashed, get a backtrace of the function calls leading to it:\n```console\n(gdb) bt\n```\n\nFor a more comprehensive guide check [Beej's Quick Guide to GDB](https://beej.us/guide/bggdb/)\n\n## Support\n\nProblems? Check out our [Discord Server][discord-invite]\n\n## Contributing\n\nAll kinds of contributions are welcome, all we ask is to abide to our [guidelines](docs/CONTRIBUTING.md)! If you want to help but is unsure where to get started then our [Discord API Roadmap](docs/DISCORD_ROADMAP.md) is a good starting point. Check our [links](#links) for more helpful information.\n\n## Getting Started\n\n- [Documentation](https://cogmasters.github.io/concord/)\n- [Discord API Roadmap](docs/DISCORD_ROADMAP.md)\n\n## Useful links\n\n- [Migrating from V1][migrating-link]\n- [Migrating from Orca][migrating-orca-link]\n","funding_links":[],"categories":["Miscellaneous","API Libraries","Web Frameworks","C","Web框架","Libraries"],"sub_categories":["YAML","C","Discord"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCogmasters%2Fconcord","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FCogmasters%2Fconcord","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCogmasters%2Fconcord/lists"}