├── .gitattributes ├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── LICENSE ├── README.md ├── bin ├── dpp.dll ├── fmtd.dll ├── libcrypto-1_1-x64.dll ├── libsodium.dll ├── libssl-1_1-x64.dll ├── opus.dll └── zlib1.dll ├── src ├── CMakeLists.txt ├── discord_bot │ ├── discord.cpp │ ├── discord.h │ └── structure │ │ └── bot_settings.h ├── main.cpp └── utils │ └── quick_hash.h └── vendor └── CMakeLists.txt /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode/ 2 | .vs/ 3 | build/ 4 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "vendor/DPP"] 2 | path = vendor/DPP 3 | url = https://github.com/brainboxdotcc/DPP 4 | [submodule "vendor/fmtdor/DPP"] 5 | path = vendor/fmtdor/DPP 6 | url = https://github.com/fmtlib/fmt 7 | [submodule "vendor/fmt"] 8 | path = vendor/fmt 9 | url = https://github.com/fmtlib/fmt 10 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.22) 2 | project(discord_bot_cpp) 3 | 4 | set(CMAKE_CXX_STANDARD 20) 5 | 6 | add_subdirectory(src) 7 | add_subdirectory(vendor) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # discord-bot-cpp 2 | a discord bot written in c++ 3 | 4 | ## How to build the source - starting path (discord-bot-cpp/) 5 | ```shell 6 | $ mkdir build 7 | $ cd build 8 | $ cmake .. 9 | $ cmake --build . 10 | ``` 11 | 12 | ## Running the program 13 | - copy a executable file (`discord_bot.exe`) from `discord-bot-cpp/build/src/debug` to `discord-bot-cpp/bin` 14 | - run the program. 15 | 16 | ## Credits 17 | - [fmtlib - fmt](https://github.com/fmtlib/fmt) 18 | - [brainboxdotcc - DPP](https://github.com/brainboxdotcc/DPP) 19 | -------------------------------------------------------------------------------- /bin/dpp.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RebillionXX/discord-bot-cpp/930d2e8bb6b29f832a0c1ad67b4fd996cb98857d/bin/dpp.dll -------------------------------------------------------------------------------- /bin/fmtd.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RebillionXX/discord-bot-cpp/930d2e8bb6b29f832a0c1ad67b4fd996cb98857d/bin/fmtd.dll -------------------------------------------------------------------------------- /bin/libcrypto-1_1-x64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RebillionXX/discord-bot-cpp/930d2e8bb6b29f832a0c1ad67b4fd996cb98857d/bin/libcrypto-1_1-x64.dll -------------------------------------------------------------------------------- /bin/libsodium.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RebillionXX/discord-bot-cpp/930d2e8bb6b29f832a0c1ad67b4fd996cb98857d/bin/libsodium.dll -------------------------------------------------------------------------------- /bin/libssl-1_1-x64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RebillionXX/discord-bot-cpp/930d2e8bb6b29f832a0c1ad67b4fd996cb98857d/bin/libssl-1_1-x64.dll -------------------------------------------------------------------------------- /bin/opus.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RebillionXX/discord-bot-cpp/930d2e8bb6b29f832a0c1ad67b4fd996cb98857d/bin/opus.dll -------------------------------------------------------------------------------- /bin/zlib1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RebillionXX/discord-bot-cpp/930d2e8bb6b29f832a0c1ad67b4fd996cb98857d/bin/zlib1.dll -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(discord_bot LANGUAGES CXX) 2 | 3 | file(GLOB INCLUDE_FILES 4 | *.h 5 | discord_bot/*.h 6 | discord_bot/structure/*.h 7 | utils/*.h 8 | ) 9 | file(GLOB SOURCE_FILES 10 | *.cpp 11 | discord_bot/*.cpp 12 | discord_bot/structure/*.cpp 13 | utils/*.cpp 14 | ) 15 | 16 | add_executable(${PROJECT_NAME} 17 | ${INCLUDE_FILES} 18 | ${SOURCE_FILES} 19 | ) 20 | 21 | set_target_properties(${PROJECT_NAME} PROPERTIES 22 | C_STANDARD 11 23 | CXX_STANDARD 20 24 | CXX_STANDARD_REQUIRED ON 25 | ) 26 | 27 | target_compile_definitions(${PROJECT_NAME} PUBLIC 28 | NOMINMAX 29 | WIN32_LEAN_AND_MEAN 30 | ) 31 | 32 | target_include_directories(${PROJECT_NAME} PRIVATE 33 | ${CMAKE_CURRENT_SOURCE_DIR} 34 | ${CMAKE_CURRENT_SOURCE_DIR}/../vendor/DPP/include 35 | ${CMAKE_CURRENT_SOURCE_DIR}/../vendor/fmt/include 36 | ) 37 | 38 | target_link_libraries(${PROJECT_NAME} 39 | dpp 40 | fmt 41 | ) 42 | -------------------------------------------------------------------------------- /src/discord_bot/discord.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | namespace discord 8 | { 9 | discord_bot::discord_bot(const bot_settings& settings) : m_settings(settings) { 10 | fmt::print("discord-bot-cpp V0.0.1 starting...\n"); 11 | } 12 | discord_bot::~discord_bot() { 13 | delete m_bot; 14 | } 15 | void discord_bot::init() { 16 | uint32_t intents = 17 | dpp::intents::i_default_intents | 18 | dpp::intents::i_message_content | 19 | dpp::intents::i_guild_presences; 20 | m_bot = new dpp::cluster(m_settings.m_token, intents); 21 | 22 | m_bot->on_interaction_create([this](const dpp::interaction_create_t& event) { this->on_interaction_create(event); }); 23 | m_bot->on_message_create([this](const dpp::message_create_t& event) { this->on_message_create(event); }); 24 | m_bot->on_ready([&](const dpp::ready_t& event) { 25 | if (dpp::run_once()) { 26 | this->register_commands(); 27 | fmt::print("[discord-bot]: {} is now online.\n", m_bot->me.format_username()); 28 | } 29 | }); 30 | std::thread([&] { 31 | this->m_bot->start(false); 32 | }).detach(); 33 | } 34 | void discord_bot::register_commands() { 35 | m_bot->guild_command_create(dpp::slashcommand{ 36 | "ping", "ping pong!", m_bot->me.id }. 37 | add_permission(dpp::command_permission(947758500912701440, dpp::command_permission_type::cpt_user, true)), 38 | m_settings.m_guild_id); 39 | } 40 | 41 | void discord_bot::on_message_create(const dpp::message_create_t& event) { 42 | if (event.msg.content.starts_with("!help")) 43 | event.reply("no helps for you."); 44 | } 45 | void discord_bot::on_interaction_create(const dpp::interaction_create_t& event) { 46 | using namespace utils; 47 | uint64_t hash = quick_hash(event.command.get_command_name()); 48 | switch (hash) { 49 | case "ping"_qh: { 50 | event.reply("pong!"); 51 | } break; 52 | default: 53 | break; 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /src/discord_bot/discord.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace discord 6 | { 7 | class discord_bot { 8 | public: 9 | discord_bot(const bot_settings& settings); 10 | ~discord_bot(); 11 | 12 | [[nodiscard]] dpp::cluster* get() const { return m_bot; } 13 | void init(); 14 | void register_commands(); 15 | 16 | void on_message_create(const dpp::message_create_t& event); 17 | void on_interaction_create(const dpp::interaction_create_t& event); 18 | public: 19 | bot_settings m_settings; 20 | dpp::cluster* m_bot; 21 | 22 | bool m_ready = false; 23 | }; 24 | }; -------------------------------------------------------------------------------- /src/discord_bot/structure/bot_settings.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace discord 6 | { 7 | struct bot_settings { 8 | std::string m_token; 9 | dpp::snowflake m_guild_id; 10 | }; 11 | }; -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace discord; 5 | discord_bot* g_discord; 6 | 7 | int main() { 8 | g_discord = new discord_bot({ "YOUR TOKEN", 0x0 /* <- your server id*/ }); 9 | g_discord->init(); 10 | while (true); 11 | } -------------------------------------------------------------------------------- /src/utils/quick_hash.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace utils { 5 | constexpr uint32_t quick_hash(const std::string_view& data) { 6 | uint32_t hash = 5381; 7 | for (const auto& c : data) 8 | hash = ((hash << 5) + hash) + c; 9 | return hash; 10 | } 11 | constexpr uint32_t operator "" _qh(const char* str, std::size_t len) { 12 | return utils::quick_hash(std::string_view{ str, len }); 13 | } 14 | } -------------------------------------------------------------------------------- /vendor/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.22) 2 | project(discord_bot_cpp) 3 | 4 | add_subdirectory(DPP) 5 | add_subdirectory(fmt) --------------------------------------------------------------------------------