唯一外部依赖是 curl-7.56.1 或更高,从源码编译 libcurl 时需启用 SSL 支持;Windows 仅支持 Cygwin,Mingw64 和 Msys2 不受支持;非 Linux 系统可能需用 CFLAGS/LDFLAGS 指定 libcurl 头文件与库路径。
concord
CogmastersMIT活跃维护用 C 语言写的 Discord API 封装库,方便开发者用 C 构建 Discord 机器人和客户端,处理 REST 请求与 WebSocket 连接。
A Discord API wrapper library made in C
# apt update && apt install -y libcurl4-openssl-dev
git clone https://github.com/cogmasters/concord.git && cd concord
makeREADME 未说明显存或 GPU 要求;支持 GNU/Linux 4.x、FreeBSD 12、NetBSD 8.1、Windows 7 (Cygwin)、GNU/Hurd 0.9、Mac OS X 10.9,不支持大端处理器系统。
用 C99 编写的异步 Discord API 封装库,把官方文档低层映射成 C 代码,依赖极少
用 C 语言写的 Discord API 封装库,方便开发者用 C 构建 Discord 机器人和客户端,处理 REST 请求与 WebSocket 连接。
核心能力
- 异步 C99 实现,仅依赖 curl-7.56.1 及以上
- 低层映射 Discord 官方文档到 C 结构体与函数
- 支持斜杠命令与消息事件回调注册
- 内置 cog-utils、log.c、carray 等打包依赖
- 提供 config.json 免重编译配置机器人
容易踩的坑
- v3.0.1Release v3.0.1 (withdrawn)pre-release2026-06-23 · 2026-06-23 20:27 UTC
查看更新说明
What's Changed
- Apply log config to the client logger by @lcsmuller in https://github.com/Cogmasters/concord/pull/234
- fix(build): bump reflect-c for portable code generation by @lcsmuller in https://github.com/Cogmasters/concord/pull/235
- Replace
curl_multi_socket_allforcurl_multi_socket_actionby @ThePedroo in https://github.com/Cogmasters/concord/pull/238 - Add autocomplete example by @Kolin63 in https://github.com/Cogmasters/concord/pull/239
New Contributors
- @Kolin63 made their first contribution in https://github.com/Cogmasters/concord/pull/239
Full Changelog: https://github.com/Cogmasters/concord/compare/v3.0.0...v3.0.1
- v3.0.0Release v3.0.0 (withdrawn)pre-release2026-06-12 · 2026-06-12 01:04 UTC
查看更新说明
What's Changed
- Chore/remove deprecated voice by @lcsmuller in https://github.com/Cogmasters/concord/pull/201
- Refactor logger architecture by @lcsmuller in https://github.com/Cogmasters/concord/pull/200
- Refactor/update deps by @lcsmuller in https://github.com/Cogmasters/concord/pull/202
- Fix/logger fixes by @lcsmuller in https://github.com/Cogmasters/concord/pull/204
- Add new method for initializing client by @lcsmuller in https://github.com/Cogmasters/concord/pull/205
- Decouple global-init logic by @lcsmuller in https://github.com/Cogmasters/concord/pull/206
- Fix/config init by @lcsmuller in https://github.com/Cogmasters/concord/pull/207
- Add alias for legacy shutdown function by @lcsmuller in https://github.com/Cogmasters/concord/pull/209
- Fix/make shared duplicate linkage by @lcsmuller in https://github.com/Cogmasters/concord/pull/215
- Re-add Solaris support and fix Makefile by @HackerSmacker in https://github.com/Cogmasters/concord/pull/213
- fix: _queriec_add() incorrect parameter concatenation by @cyberc001 in https://github.com/Cogmasters/concord/pull/212
- SONAME support by @HackerSmacker in https://github.com/Cogmasters/concord/pull/193
- Fix linker order to resolve curl_global_init undefined symbol by @Copilot in https://github.com/Cogmasters/concord/pull/219
- fix(rest_request): Fix double free of request body. by @InterLinked1 in https://github.com/Cogmasters/concord/pull/229
- Fix: stage_instance and sticker endpoints broken since 2022, never compiled into libdiscord.a by @Risim-hanse in https://github.com/Cogmasters/concord/pull/230
- fix(discord-events): add const qualifier on command parameters for consistency and type correctness by @Risim-hanse in https://github.com/Cogmasters/concord/pull/232
- Add hermetic suite scaffolding: Units, REST/rate-limit integration, gateway mock transport by @lcsmuller in https://github.com/Cogmasters/concord/pull/233
- Refactor/gencodecs replace with reflectc by @lcsmuller in https://github.com/Cogmasters/concord/pull/217
- Release v3.0.0 by @lcsmuller in https://github.com/Cogmasters/concord/pull/203
New Contributors
- @cyberc001 made their first contribution in https://github.com/Cogmasters/concord/pull/212
- @Copilot made their first contribution in https://github.com/Cogmasters/concord/pull/219
- @Risim-hanse made their first contribution in https://github.com/Cogmasters/concord/pull/230
Full Changelog: https://github.com/Cogmasters/concord/compare/v2.4.0...v3.0.0
- v2.4.0Release v2.4.0最新正式版2025-04-23 · 2025-04-23 22:37 UTC
What's Changed
- Add a dev branch notice by @mazylol in https://github.com/Cogmasters/concord/pull/182
- Add Components V2 by @ThePedroo in fb0f834
Full Changelog: https://github.com/Cogmasters/concord/compare/v2.3.0...v2.4.0
- v2.3.0Release v2.3.02024-09-13 · 2024-09-13 19:46 UTC
查看更新说明
What's Changed
- docs(README.md): fix broken links in 'Build Instructions' section by @jdeokkim in https://github.com/Cogmasters/concord/pull/164
- docs(README.md): fix a typo in 'Build Instructions' section by @jdeokkim in https://github.com/Cogmasters/concord/pull/165
- Sudden shutdowns when TLS connection is ended by @lcsmuller in https://github.com/Cogmasters/concord/pull/155
- chore(core/sha1): removed SHA1 helper function by @Suwup in https://github.com/Cogmasters/concord/pull/167
- Fix permanent shutdowns (TLS & 1000 close code) by @ThePedroo in https://github.com/Cogmasters/concord/pull/168
- fix(concord-once): make signal safe, and use a proper init counter by @Anotra in https://github.com/Cogmasters/concord/pull/170
- Release v2.3.0 by @ThePedroo in https://github.com/Cogmasters/concord/pull/181
New Contributors
- @Suwup made their first contribution in https://github.com/Cogmasters/concord/pull/167
Full Changelog: https://github.com/Cogmasters/concord/compare/v2.2.1...v2.3.0
- v2.2.1v2.2.1 release2023-07-08 · 2023-07-08 20:18 UTC
查看更新说明
What's Changed
- Added AUR Package by @mrtuxa in https://github.com/Cogmasters/concord/pull/122
- Add config.json guide to Concord by @ThePedroo in https://github.com/Cogmasters/concord/pull/116
- docs(guides): add sqlite3 with concord guide by @ThePedroo in https://github.com/Cogmasters/concord/pull/117
- docs(guide): add debugging guide by @ThePedroo in https://github.com/Cogmasters/concord/pull/118
- docs(guide): add env guide by @ThePedroo in https://github.com/Cogmasters/concord/pull/121
- docs(guide): add installing on termux guide by @ThePedroo in https://github.com/Cogmasters/concord/pull/123
- docs(guide): add embeds guide by @ThePedroo in https://github.com/Cogmasters/concord/pull/124
- Examples-Makefile optional compiler assignment by @SoujiThenria in https://github.com/Cogmasters/concord/pull/143
- Release v2.2.1 by @lcsmuller in https://github.com/Cogmasters/concord/pull/147
New Contributors
- @mrtuxa made their first contribution in https://github.com/Cogmasters/concord/pull/122
- @SoujiThenria made their first contribution in https://github.com/Cogmasters/concord/pull/143
Full Changelog: https://github.com/Cogmasters/concord/compare/v2.2.0...v2.2.1
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
Concord - C Discord API library
🚨 Concord is not dead! 🚨
Development 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.
About
Concord is an asynchronous C99 Discord API library with minimal external dependencies, and a low-level translation of the Discord official documentation to C code.
Examples
The following are minimalistic examples, refer to examples/ for a better overview.
Slash Commands (new method)
Note: you need to replace GUILD_ID with an actual guild ID, or this example won't compile!
You can use a macro to do this: #define GUILD_ID 1234567898765431
#include <string.h>
#include <concord/discord.h>
void on_ready(struct discord *client, const struct discord_ready *event) {
struct discord_create_guild_application_command params = {
.name = "ping",
.description = "Ping command!"
};
discord_create_guild_application_command(client, event->application->id,
GUILD_ID, ¶ms, NULL);
}
void on_interaction(struct discord *client, const struct discord_interaction *event) {
if (event->type != DISCORD_INTERACTION_APPLICATION_COMMAND)
return; /* return if interaction isn't a slash command */
if (strcmp(event->data->name, "ping") == 0) {
struct discord_interaction_response params = {
.type = DISCORD_INTERACTION_CHANNEL_MESSAGE_WITH_SOURCE,
.data = &(struct discord_interaction_callback_data){
.content = "pong"
}
};
discord_create_interaction_response(client, event->id,
event->token, ¶ms, NULL);
}
}
int main(void) {
struct discord *client = discord_init(BOT_TOKEN);
discord_set_on_ready(client, &on_ready);
discord_set_on_interaction_create(client, &on_interaction);
discord_run(client);
}
Message Commands (old method)
#include <string.h>
#include <concord/discord.h>
#include <concord/log.h>
void on_ready(struct discord *client, const struct discord_ready *event) {
log_info("Logged in as %s!", event->user->username);
}
void on_message(struct discord *client, const struct discord_message *event) {
if (strcmp(event->content, "ping") == 0) {
struct discord_create_message params = { .content = "pong" };
discord_create_message(client, event->channel_id, ¶ms, NULL);
}
}
int main(void) {
struct discord *client = discord_init(BOT_TOKEN);
discord_add_intents(client, DISCORD_GATEWAY_MESSAGE_CONTENT);
discord_set_on_ready(client, &on_ready);
discord_set_on_message_create(client, &on_message);
discord_run(client);
}
Supported operating systems (minimum requirements)
- GNU/Linux 4.x
- FreeBSD 12
- NetBSD 8.1
- Windows 7 (Cygwin)
- GNU/Hurd 0.9
- Mac OS X 10.9
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.
Build Instructions
The 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.
On Windows
- Install Cygwin
- Make sure that you installed libcurl, gcc, make, and git when you ran the Cygwin installer!
- You will want to check the Windows tutorial here!
- Mingw64 and Msys2 are currently NOT supported. Please see this for more information.
- Once installed, compile it normally like you would on UNIX/Linux/OS X/BSD.
- Note: you will likely need to include
-L/usr/local/lib -I/usr/local/includeon yourgcccommand, or in yourCFLAGSvariable in your Makefile for your bot.
On Linux, BSD, and Mac OS X
(note -- # means that you should be running as root)
Ubuntu and Debian
# apt update && apt install -y libcurl4-openssl-dev
Void Linux
# xbps-install -S libcurl-devel
Alpine
# apk add curl-dev
FreeBSD
# pkg install curl
OS X
- Note: you will need to install Xcode, or at a minimum, the command-line tools with
xcode-select --install.
$ brew install curl (Homebrew)
$ port install curl (MacPorts)
Arch Linux / Manjaro (Arch based)
git clone https://aur.archlinux.org/concord-git.git
cd concord-git
makepkg -Acs
pacman -U concord-git-version-any.pkg.tar.zst
Alternatively, you can use an AUR helper:
yay -S concord-git
Setting up your environment
Clone Concord into your workspace
$ git clone https://github.com/cogmasters/concord.git && cd concord
Compile Concord
$ make
Special notes for non-Linux systems
You might run into trouble with the compiler and linker not finding your Libcurl headers. You can do something like this:
$ CFLAGS=-I<some_path> LDFLAGS=-L<some_path> make
For instance, on a FreeBSD system:
$ CFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib make
On OS X using MacPorts:
$ CFLAGS=-I/opt/local/include LDFLAGS=-L/opt/local/lib make
On OS X using a self-compiled libcurl:
$ CFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/include make
On Windows with Cygwin, you might need to pass both arguments to use POSIX threading:
$ CFLAGS="-pthread -lpthread" make
Special note about linking Concord against another library
In some cases, you might want to link Concord into a shared object, or link it as a shared object into another shared
object. In that case, you will need to compile Concord with CFLAGS="-fpic" make.
Configuring Concord
discord_config_init() is the initialization method that allows configuring your bot without recompiling.
The following outlines config.json fields:
{
"logging": { // logging directives
"level": "trace", // trace, debug, info, warn, error, fatal
"filename": "bot.log", // the log output file
"quiet": false, // change to true to disable logs in console
"overwrite": true, // overwrite file if already exists, append otherwise
"use_color": true, // display color for log entries
"http": {
"enable": true, // generate http specific logging
"filename": "http.log" // the HTTP log output file
},
"disable_modules": ["WEBSOCKETS", "USER_AGENT"] // disable logging for these modules
},
"discord": { // discord directives
"token": "YOUR-BOT-TOKEN", // replace with your bot token
"default_prefix": {
"enable": false, // enable default command prefix
"prefix": "YOUR-COMMANDS-PREFIX" // replace with your prefix
}
},
... // here you can add your custom fields *
}
* Your custom field contents can be fetched with discord_config_get_field()
Test Copycat-Bot
- Get your bot token and add it to
config.json, by assigning it to discord's "token" field. There are well written instructions from discord-irc explaining how to get your bot token and adding it to a server. - Build example executables:
$ make examples - Run Copycat-Bot:
$ cd examples && ./copycat
Get Copycat-Bot Response
Type a message in any channel the bot is part of and the bot should send an exact copy of it in return.
Terminate Copycat-Bot
With Ctrl+c or with Ctrl+|
Configure your build
The following outlines special flags and targets to override the default Makefile build with additional functionalities.
Special compilation flags
-DCCORD_SIGINTCATCH- By default Concord will not shutdown gracefully when a SIGINT is received (i.e. Ctrl+c), enable this flag if you wish it to be handled for you.
-DCCORD_DEBUG_WEBSOCKETS- Enable verbose debugging for WebSockets communication.
-DCCORD_DEBUG_HTTP- Enable verbose debugging for HTTP communication.
Example:
$ CFLAGS="-DCCORD_SIGINTCATCH -DCCORD_DEBUG_HTTP" make
Special targets
make shared- Produce a dynamically-linked version of Concord. This Makefile is intended for GNU-style compilers, such as
gccorclang.
- Produce a dynamically-linked version of Concord. This Makefile is intended for GNU-style compilers, such as
make shared_osx- Produce a dynamically-linked version of Concord, for OS X and Darwin systems.
make voice- Enable experimental Voice Connection handling - not production ready.
make debug- Enable some flags useful while developing, such as
-O0and-g
- Enable some flags useful while developing, such as
Installing Concord
(note -- # means that you should be running as root)
# make install
This will install the headers and library files into $PREFIX. You can override this as such:
# PREFIX=/opt/concord make install
Cross-compiling Concord
To cross-compile Concord, see the manual here.
Included dependencies
The following are stable and well documented dependencies that are packaged with Concord and can be included to your projects:
| File | Description |
|---|---|
| cog-utils | General purpose functions aimed at portability |
| log.c* | A simple C99 logging library |
| carray* | Macro-based implementation of type-safe arrays |
| anomap* | Sorted key/value storage for C99 |
| chash* | Macro-based implementation of type-safe hashtables |
| json-build | Tiny, zero-allocation JSON serializer |
| jsmn-find | Tiny, zero-allocation JSON tokenizer |
* Concord uses its own modified version that may be not up to date with the original
Note that included headers must be concord/ prefixed:
#include <concord/discord.h>
#include <concord/log.h>
Standalone executable
GCC
$ gcc myBot.c -o myBot -pthread -ldiscord -lcurl
Clang
$ clang myBot.c -o myBot -pthread -ldiscord -lcurl
UNIX C compilers
This includes the following compilers:
- IBM XL C/C++ (AIX, z/OS, IBM i)
- Sun/Oracle Studio (Solaris)
- IRIX MIPSpro C++ (IRIX) -- NOTE: currently not supported
- HP aCC (HP-UX)
- Compaq C (Tru64 UNIX) -- NOTE: also currently not supported Note: if you want to actually compile this on one of the systems listed above, please see the "Compiling on old computers" guide.
$ cc myBot.c -o myBot -ldiscord -lcurl -lpthread
Note: some systems such as Cygwin require you to do this:
$ gcc myBot.c -o myBot -pthread -lpthread -ldiscord -lcurl
(this links against libpthread.a in /usr/lib)
Recommended debuggers
First, make sure your executable is compiled with the -g flag to ensure human-readable debugger messages.
Valgrind
Using valgrind to check for memory leaks:
valgrind --leak-check=full ./myBot
For a more comprehensive guide check Valgrind's Quick Start.
GDB
Using GDB to check for runtime errors, such as segmentation faults:
$ gdb ./myBot
And then execute your bot from the gdb environment:
(gdb) run
If the program has crashed, get a backtrace of the function calls leading to it:
(gdb) bt
For a more comprehensive guide check Beej's Quick Guide to GDB
Support
Problems? Check out our Discord Server
Contributing
All kinds of contributions are welcome, all we ask is to abide to our guidelines! If you want to help but is unsure where to get started then our Discord API Roadmap is a good starting point. Check our links for more helpful information.