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
Message Commands (old method)
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
Void Linux
Alpine
FreeBSD
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)
Alternatively, you can use an AUR helper:
Setting up your environment
Clone Concord into your workspace
Compile Concord
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:
For instance, on a FreeBSD system:
On OS X using MacPorts:
On OS X using a self-compiled libcurl:
On Windows with Cygwin, you might need to pass both arguments to use POSIX threading:
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:
- 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.
- By default Concord will not shutdown gracefully when a SIGINT is received (i.e.
-DCCORD_DEBUG_WEBSOCKETS- Enable verbose debugging for WebSockets communication.
-DCCORD_DEBUG_HTTP- Enable verbose debugging for HTTP communication.
Example:
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)*
This will install the headers and library files into $PREFIX. You can override this as such:
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:
- Concord uses its own modified version that may be not up to date with the original
Note that included headers must be concord/ prefixed:
Standalone executable
GCC
Clang
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.
Note: some systems such as Cygwin require you to do this:
(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:
For a more comprehensive guide check Valgrind's Quick Start.
GDB
Using GDB to check for runtime errors, such as segmentation faults:
And then execute your bot from the gdb environment:
If the program has crashed, get a backtrace of the function calls leading to it:
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.
