A Discord API wrapper library made in C
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.
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.
The following are minimalistic examples, refer to examples/ for a better overview.
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
……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.
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.
-L/usr/local/lib -I/usr/local/include on your gcc command, or in your CFLAGS variable in your Makefile for your bot.(note -- # means that you should be running as root)
# apt update && apt install -y libcurl4-openssl-dev# xbps-install -S libcurl-devel# apk add curl-dev# pkg install curlxcode-select --install.$ brew install curl (Homebrew)
$ port install curl (MacPorts)git clone https://aur.archlinux.org/concord-git.git
cd concord-git
makepkg -Acs
pacman -U concord-git-version-any.pkg.tar.zstAlternatively, you can use an AUR helper:
yay -S concord-git$ git clone https://github.com/cogmasters/concord.git && cd concord$ makeYou might run into trouble with the compiler and linker not finding your Libcurl headers. You can do something like this:
$ CFLAGS=-I LDFLAGS=-L makeFor instance, on a FreeBSD system:
$ CFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib makeOn OS X using MacPorts:
$ CFLAGS=-I/opt/local/include LDFLAGS=-L/opt/local/lib makeOn OS X using a self-compiled libcurl:
$ CFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/include makeOn Windows with Cygwin, you might need to pass both arguments to use POSIX threading:
$ CFLAGS="-pthread -lpthread" makeIn 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.
discord_config_init() is the initialization method that allows configuring your bot without recompiling.
The following outlines config.json fields:
…* Your custom field contents can be fetched with discord_config_get_field()
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.$ make examples$ cd examples && ./copycatType a message in any channel the bot is part of and the bot should send an exact copy of it in return.
With Ctrl+c or with Ctrl+|
The following outlines special flags and targets to override the default Makefile build with additional functionalities.
-DCCORD_SIGINTCATCH-DCCORD_DEBUG_WEBSOCKETS-DCCORD_DEBUG_HTTPExample:
$ CFLAGS="-DCCORD_SIGINTCATCH -DCCORD_DEBUG_HTTP" makemake sharedgcc or clang.make shared_osxmake voicemake debug-O0 and -g(note -- # means that you should be running as root)
# make installThis will install the headers and library files into $PREFIX. You can override this as such:
# PREFIX=/opt/concord make installTo cross-compile Concord, see the manual here.
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
#include $ gcc myBot.c -o myBot -pthread -ldiscord -lcurl$ clang myBot.c -o myBot -pthread -ldiscord -lcurl$ cc myBot.c -o myBot -ldiscord -lcurl -lpthreadNote: 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)
First, make sure your executable is compiled with the -g flag to ensure human-readable debugger messages.
Using valgrind to check for memory leaks:
valgrind --leak-check=full ./myBotFor a more comprehensive guide check Valgrind's Quick Start.
Using GDB to check for runtime errors, such as segmentation faults:
$ gdb ./myBotAnd then execute your bot from the gdb environment:
(gdb) runIf the program has crashed, get a backtrace of the function calls leading to it:
(gdb) btFor a more comprehensive guide check Beej's Quick Guide to GDB
Problems? Check out our Discord Server
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.
No open issues yet, or sync has not completed.