Hello, and welcome to DiscordCoreAPI! This is a Discord bot library, written in C++, that leverages custom asynchronous CoRoutines, as well as a home-brew set of Https, WebSocket, and Datagram socket clients - all to deliver the utmost performance and efficiency for your bot. It uses roughly 0.1% of an Intel i7 9750h CPU to stream audio in high quality (Opus @ 48Khz, 16-bit) to a single server.
This is a link to the Discord server!
A template for utilizing this library.
- Using the
discord_core_api::snowflake::toEntity()
function of thesnowflake
class allows for converting the entity's id directly into the data structure represented by it.
discord_core_api::snowflake someChannelId{};
discord_core_api::channel_data newChannel = someChannelId.toEntity<discord_core_api::channel_data>();
std::cout << "CHANNEL NAME: " + newChannel.name << std::endl;
- Thanks to utilizing Erlang Text Format for websocket transfer, and a pool of kept-alive HTTPS connections - this library offers the snappiest responses to your interactions and user input.
- Connect multiple voice-channels to one-another using the
StreamInfo
member of theVoiceConnectInitData
structure, with theVoiceConnection
class.
- It only uses about 0.1% of an Intel i7 9750h to stream audio in high quality (Opus 48Khz 16-bit Stereo) to a single server.
- All of the Discord API endpoints are covered in this library, including voice communication.
- As a result of using custom asynchronous coroutines along with a thread pool, this library has the ability to make fully asynchronous/concurrent requests to the Discord API.
- Guarantees that the order in which HTTPS requests are executed is the same that they were submitted in - despite being launched across different threads, while never infracting on any of the Discord API's rate-limits and while running concurrently across all of the endpoints.
- User interactions (Application Commands, Message Commands, User Commands) are accepted via the
event_manager::onInputEventCreation
event. - They can all be responded to using the
input_events::respondToInputEventAsync()
function. - Alternatively you can implement your own input-event handling by using the raw
event_manager::onInteractionCreation
orevent_manager::onMessageCreation
events.
EmbedData newEmbed{};
newEmbed.setAuthor(args.eventData.getUserName(), args.eventData.getAvatarURL());
newEmbed.setDescription("------\\n__**Sorry, but there's already something play
ing!**__\\n------");
newEmbed.setTimeStamp(getTimeAndDate());
newEmbed.setTitle("__**Playing Issue:**__");
newEmbed.setColor(discordGuild.data.borderColor);
RespondToInputEventData dataPackage{ args.eventData };
dataPackage.addMessageEmbed(newEmbed);
dataPackage.setResponseType(InputEventResponseType::Ephemeral_Interaction_Response);
InputEventData newEvent = input_events::respondToInputEvent(dataPackage);
input_events::deleteInputEventResponseAsync(newEvent, 20000).get();
- Install vcpkg, if need be.
- Make sure to run
vcpkg integrate install
. - Enter within a terminal
vcpkg install discordcoreapi:x64-windows_OR_linux
. - Set up a console project in your IDE and make sure to set the C++ standard to C++20 or later - and include
discordcoreapi/Index.hpp
. - Build and run!
- CMake (Version 3.20 or greater)
- NOTE: I installed these using the vcpkg installer.
- DiscordCoreAPI (.\vcpkg install jsonifier:x64-windows_OR_linux)
- OpenSSL (.\vcpkg install openssl:x64-windows_OR_linux)
- Opus (.\vcpkg install opus:x64-windows_OR_linux)
- Sodium (.\vcpkg install libsodium:x64-windows_OR_linux)
- Install the dependencies.
- Clone this git repository into a folder.
- Set, in CMakeLists.txt, the
_VCPKG_ROOT_DIR
, or theOpus_DIR
,unofficial-sodium_DIR
paths to wherever each of the respective dependency files are located and they are as follows:- Opus_DIR # Set this one to the folder location of the file "OpusConfig.cmake".
- unofficial-sodium_DIR # Set this one to the folder location of the file "unofficial-sodiumConfig.cmake".
- OPENSSL_ROOT_DIR # Set this one to the folder location of the include folder and library folders of OpenSSL.
- Open a terminal inside the git repo's folder.
- Run
cmake -S . --preset Linux_OR_Windows-Debug_OR_Release
. - Then run
cmake --build --preset Linux_OR_Windows-Debug_OR_Release
. - Run within the same terminal and folder
cmake --install ./Build/Debug_OR_Release
. - The default installation paths are: Windows = "ROOT_DRIVE:/Users/USERNAME/CMake/DiscordCoreAPI", Linux = "/home/USERNAME/CMake/DiscordCoreAPI"
- By running
cmake --install ./Build/Debug_OR_Release
, you will be given a cmake package, which can be used to build from this library, using other cmake projects. - It is used by setting
DiscordCoreAPI_DIR
to wherever the DiscordCoreAPIConfig.cmake file would have been installed on your system by having run thecmake --install
command, and then usingfind_package()
onDiscordCoreAPI
. - When found, you will be granted the following cmake "variables";
DiscordCoreAPI
- this is the library target which can be linked to from other targets in cmake, and on Windows;$<TARGET_RUNTIME_DLLS:DiscordCoreAPI-Bot>
- which is a list of dll files to be copied into your executable's final location after building. As well asRELEASE_PDB_FILE_PATH
,DEBUG_PDB_FILE_PATH
,RELEASE_PDB_FILE_NAME
, andDEBUG_PDB_FILE_NAME
, which are full file/directory paths/filenames to the library's PDB files. - Here and here is an example of building an executable from this library with this method.
- Download the bot template or create your own with the same imports, and set within it either the
VCPKG_ROOT_DIR
, or theCMAKE_CONFIG_FILE_DIR
,Opus_DIR
, andunofficial-sodium_DIR
paths to wherever each of the respective dependency files are located and they are as follows:- CMAKE_CONFIG_FILE_DIR # Set this one to the folder location of the DiscordCoreAPIConfig.cmake generated while running CMake --install.
- Opus_DIR # Set this one to the folder location of the file "OpusConfig.cmake".
- unofficial-sodium_DIR # Set this one to the folder location of the file "unofficial-sodiumConfig.cmake".
- OPENSSL_ROOT_DIR # Set this one to the folder location of the include folder and library folders of OpenSSL.
- Set up a main.cpp like this one, including the header
discordcoreapi/Index.hpp
. - Run in a terminal from within the same folder as the top-level CMakeLists.txt,
cmake -S . --preset Linux_OR_Windows-Debug_OR_Release
. - Then run
cmake --build --preset Linux_OR_Windows-Debug_OR_Release
. - Run within the same terminal and folder
cmake --install ./Build/Debug_OR_Release
. - The default installation paths are: Windows = "ROOT_DRIVE:/Users/USERNAME/CMake/Bot-Template-For-DiscordCoreAPI", Linux = "/home/USERNAME/CMake/Bot-Template-For-DiscordCoreAPI"
I am currently working on getting this thing to be used by people like you! So, if you have any suggestions for the library that would make it more usable - don't hesitate to let me know! I can be easily found on the Discord server that is linked to above! Cheers and thanks for your time.