Skip to content

zKevz/KCord

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KCord

KCord is C++ 17 Unofficial wrapper for the Discord API

It is designed to be as fast as possible, low memory, and reliable.

Requirement

To use this library, you would need to install these libraries:

Building

Cloning from repository:

git clone https://github.com/zKevz/KCord

Or you can add submodule

git submodule add https://github.com/zKevz/KCord

Example CMakeLists.txt :

cmake_minimum_required(VERSION 3.15)
project(ProjectName DESCRIPTION "Description" VERSION 0.1)

set(CMAKE_CXX_STANDARD 17)

add_subdirectory(KCord)

add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} PUBLIC KCord ${CMAKE_THREAD_LIBS_INIT})

Documentation

You can see the documentation in documentation tree

For simple example, you can take a look at this

Or you can check below code

#include <iostream>
#include <DiscordClient.hpp>

void OnMessage(const Discord::DiscordMessageEventInfo& info)
{
    Ptr<Discord::DiscordMessage> msg     = info.GetMsg();
    Ptr<Discord::DiscordUser>    user    = msg->GetAuthor();

    if (user->IsBot())
        return;

    info.GetClient()->InvokeCommand(msg);
}

void OnPingCommand(Discord::DiscordCommandContext* context)
{
    context->GetChannel()->Send("Pong!");
}

int main()
{
    Discord::DiscordClientConfig config;
    config.Token = "ur-token";
    config.Prefix = "&";
    config.Threshold = 250;
    config.EnableDM = false;
    config.PrefixCaseSensitive = false;

    Discord::DiscordClient client(config);

    client.OnReady([]() { std::cout << "Bot is ready!\n"; });
    client.OnMessageCreated(OnMessage);

    client.RegisterCommand("ping", OnPingCommand);
    client.Run();
}

Misc

This library is not done yet, and there is plenty features to add, such as:

  • Voice, from connecting to sending data, etc

  • More framework

However, this library provides you with Interactivity.

channel->Send("Say any word!");
    
auto predicate = [&](Discord::DiscordInteractivityPredicate* p)
{
    return p->AuthorId == author->GetId() && 
           p->ChannelId == channel->GetId();
};

auto result = context->GetInteractivity()->WaitForMessage(predicate, 10s);
// Wait for message whose author id is `author->GetId()` and channel id is `channel->GetId()`

if (result.IsSuccess)
{
    context->Reply("You said " + result.Message->GetContent() + "!");
    // Send the result
}

Contributor

Me

free#1234

Abood#1550

Alexander#9673