• Stars
    star
    134
  • Rank 270,967 (Top 6 %)
  • Language
    C++
  • License
    MIT License
  • Created over 3 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A bot library for Discord, written in C++, and featuring explicit multithreading through the usage of custom, asynchronous C++ CoRoutines.

DiscordCoreAPI

Codacy Badge Discord Commit Activity Lines of code

DiscordCoreAPI WebSite

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.

Compiler Support

MSVC_20922 GCC_12 CLANG_17

Documentation/Examples

Documentation/Examples

Discord Server

This is a link to the Discord server!

Bot Template

A template for utilizing this library.

Features

Performant

Audio-Bridge

CPU Efficient

  • 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.

Entire Discord API Covered

  • All of the Discord API endpoints are covered in this library, including voice communication.

Concurrent Discord API Access

Advanced Rate-Limiting System

  • 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.

Slash Commands and Buttons

Select Menus

User Commands

Message Commands

Modal Text Inputs

A Unified "Input-Event" System

  • User interactions (Application Commands, Message Commands, User Commands) are accepted via the DiscordCoreAPI::EventManager::onInputEventCreation event.
  • They can all be responded to using the DiscordCoreAPI::InputEvents::respondToInputEventAsync() function.
  • Alternatively you can implement your own input-event handling by using the raw DiscordCoreAPI::EventManager::onInteractionCreation or DiscordCoreAPI::EventManager::onMessageCreation events.
DiscordCoreAPI::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);
DiscordCoreAPI::RespondToInputEventData dataPackage{ args.eventData };
dataPackage.addMessageEmbed(newEmbed);
dataPackage.setResponseType(DiscordCoreAPI::InputEventResponseType::Ephemeral_Interaction_Response);
DiscordCoreAPI::InputEventData newEvent = DiscordCoreAPI::InputEvents::respondToInputEvent(dataPackage);
DiscordCoreAPI::InputEvents::deleteInputEventResponseAsync(newEvent, 20000).get();

Supported Platforms

  • This library currently supports being built within Visual Studio 2022/MSVC on the Windows platform as well as g++ 11 on the Linux platform.

Build Instructions (Full-Vcpkg)

  • 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++23 or later - and include discordcoreapi/Index.hpp.
  • Build and run!

Dependencies

  • CMake (Version 3.20 or greater)
  • NOTE: I installed these using the vcpkg installer.
  • FFMPEG (.\vcpkg install ffmpeg:x64-windows_OR_linux)
  • SimdJson (.\vcpkg install simdjson: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)

Build Instructions (Non-Vcpkg) - The Library

  • Install the dependencies.
  • Clone this git repository into a folder.
  • Set, in CMakeLists.txt, the _VCPKG_ROOT_DIR, or the FFMPEG_DIR, Opus_DIR, simdjson_DIR, and unofficial-sodium_DIR paths to wherever each of the respective dependency files are located and they are as follows:
    • FFMPEG_DIR # Set this one to the folder location of the file "FindFFMPEG.cmake".
    • Opus_DIR # Set this one to the folder location of the file "OpusConfig.cmake".
    • simdjson_DIR # Set this one to the folder location of the file "simdjson-config.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"

The CMAKE Package

  • 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 the cmake --install command, and then using find_package() on DiscordCoreAPI.
  • When found, you will be granted the following cmake "variables"; DiscordCoreAPI::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 as RELEASE_PDB_FILE_PATH, DEBUG_PDB_FILE_PATH, RELEASE_PDB_FILE_NAME, and DEBUG_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.

Build Instructions (Non-Vcpkg) - The Executable

  • Download the bot template or create your own with the same imports, and set within it either the VCPKG_ROOT_DIR, or the CMAKE_CONFIG_FILE_DIR, FFMPEG_DIR, Opus_DIR, simdjson_DIR, and unofficial-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.
    • FFMPEG_DIR # Set this one to the folder location of the file "FindFFMPEG.cmake".
    • Opus_DIR # Set this one to the folder location of the file "OpusConfig.cmake".
    • simdjson_DIR # Set this one to the folder location of the file "simdjson-config.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"

Roadmap

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.

More Repositories

1

Jsonifier

A few classes for parsing and serializing objects from/into JSON - very rapidly.
C++
15
star
2

Bot-Template-For-DiscordCoreAPI

A template for a bot, written in C++ using DiscordCoreAPI.
C++
9
star
3

MBot-GameHouse-Cpp

A game bot, written using the DiscordCoreAPI C++ Discord bot library.
C++
7
star
4

DiscordCoreAPI-Rust

The Rust version of my bot library - DiscordCoreAPI!
Rust
6
star
5

DiscordCoreLoader

A stress-tester for Discord bot libraries.
C++
5
star
6

Json-Performance

A few json-benchmarks.
C++
3
star
7

Unnamed-Renderer-Dx12

A hobby path-tracer, written using DirectX12 compute shaders.
C++
3
star
8

Spheres-DXR

A basic path-tracer, written using DirectX 12 RT-shaders.
C
3
star
9

IsItRunning

A small Windows service to keep the bots running.
C#
3
star
10

Unnamed-Renderer-DX12

3-Stage Path-Tracing Renderer
C++
3
star
11

MBot-MusicHouse-Cpp

A music bot, written using the DiscordCoreAPI C++ Discord bot library.
C++
3
star
12

DiscordcoreAPI-Docs

The documentation for the bot library - DiscordCoreAPI.
HTML
3
star
13

MBot-Janny-Cpp

A janitor bot, written using the DiscordCoreAPI C++ Discord bot library.
C++
3
star
14

Json-Benchmarks

A few benchmarks for testing the speed of the Jsonifier and simdjson libraries.
CMake
2
star
15

MBot-GameHouse

My gaming bot, written in TypeScript using Discord.js
JavaScript
2
star
16

DirectX12-Class-Library

Some of the DirectX 12 Core Interfaces, lightly wrapped and with some of my currently preferred defaults.
C++
2
star
17

Direct3D12-Compute-Hello-World-Unnamed-Renderer

Hello-world renderer, written using DirectX 12.
C++
2
star
18

MBot-Janny

My janitor Discord.js bot!
JavaScript
2
star
19

MBot-MusicHouse

My music bot, written in TypeScript using Discord.js!
JavaScript
2
star
20

Testing

Testing stuff out...
C++
2
star
21

Julia-Set-Generator-TensorFlow

A Julia set generator, written using low-level TensorFlow.
Python
2
star
22

Julia-Set-Generator-CUDA

Julia set generator written using CUDA C.
Cuda
2
star
23

Bot-Template-for-DiscordCoreAPI

A template for a bot, written in C++ using DiscordCoreAPI.
CMake
1
star
24

GertBot

C++
1
star
25

Asynchrounous-Cpp-CoRoutines

Eagerly executing potentially asynchronous C++ CoRoutines!
C++
1
star
26

DiscordCoreAPI-Linux

The Linux package of DiscordCoreAPI.
C++
1
star