Discord.C++ 0.13.0
Loading...
Searching...
No Matches
DiscordCPP::Discord Class Reference

#include <Discord.h>

Inheritance diagram for DiscordCPP::Discord:
DiscordCPP::DiscordObject

Public Member Functions

 Discord (const std::string &token, const Intents &intents, const unsigned int num_shards=0)
 
 Discord (const std::string &token, const Intents &intents, const unsigned int shard_id, const unsigned int num_shards)
 
virtual ~Discord ()
 
void start ()
 Starts the bot. This will not block.
 
void update_presence (const std::string &status, Activity activity=Activity(), const bool afk=false, const int shard_id=-1)
 updates the presence of user
 
std::vector< ApplicationCommandget_application_commands ()
 loads all application commands
 
std::vector< ApplicationCommandget_application_commands (const Guild &guild)
 loads all application commands for a guild
 
ApplicationCommand create_application_command (ApplicationCommand command)
 creates a new application command
 
- Public Member Functions inherited from DiscordCPP::DiscordObject
 DiscordObject ()=default
 
 DiscordObject (std::string token)
 
 DiscordObject (std::string token, std::string id)
 
std::string get_id () const
 

Public Attributes

Logger log
 

Protected Member Functions

std::shared_ptr< MainGatewayget_shard (const unsigned int shard_id)
 
Guildget_guild (const std::string &guild_id)
 
VoiceStateget_voice_state (const std::string &user_id, const std::string &guild_id)
 
void connect ()
 
void on_websocket_incoming_message (const json &payload)
 
void handle_raw_event (const std::string &event_name, const json &data)
 
virtual void on_ready (User user)
 called when successfully logged in
 
virtual void on_message (Message message)
 called when a Message was received
 
virtual void on_user_ban (User user, Guild guild)
 called when a Member was banned
 
virtual void on_user_unban (User user, Guild guild)
 called when a Member was unbanned
 
virtual void on_user_join (Member member, Guild guild)
 called when a User joins a Guild
 
virtual void on_user_remove (User user, Guild guild)
 called when a User is removed from a Guild (leave/kick/ban)
 
virtual void on_typing_start (User user, TextChannel channel, unsigned int timestamp)
 called when a User starts typing
 
virtual void on_interaction (Interaction interaction)
 called when an interaction was created
 
- Protected Member Functions inherited from DiscordCPP::DiscordObject
std::string get_token () const
 
json api_call (const std::string &url, const std::string &method="GET", const json &data=json(), const std::string &content_type="", const bool cache=true)
 helper function to communicate with the http api
 

Protected Attributes

std::vector< std::shared_ptr< MainGateway > > _gateways
 websocket clients
 
unsigned int _num_shards
 number of shards
 
User_user
 the user
 
std::string _application_id
 the bot's application id
 
std::vector< Guild * > _guilds
 the guilds the user is a member
 
std::map< std::string, std::vector< VoiceState * > > _voice_states
 VoiceStates by user id.
 

Friends

std::shared_ptr< VoiceClientVoiceChannel::connect ()
 

Constructor & Destructor Documentation

◆ Discord() [1/2]

DiscordCPP::Discord::Discord ( const std::string & token,
const Intents & intents,
const unsigned int num_shards = 0 )

Creates a Discord instance with one or more shards

Parameters
[in]tokenBot token for authentication
[in]intentsIntents used for the gateway.
[in]num_shards(optional) number of shards that exist (default: 0 used for automatic sharding)

◆ Discord() [2/2]

DiscordCPP::Discord::Discord ( const std::string & token,
const Intents & intents,
const unsigned int shard_id,
const unsigned int num_shards )

Creates a Discord instance with ONE shard

Parameters
[in]tokenBot token for authentication
[in]intentsIntents used for the gateway.
[in]shard_id(optional) the id of the shard (default: 0)
[in]num_shards(optional) number of shards that exist (default: 1)

◆ ~Discord()

DiscordCPP::Discord::~Discord ( )
virtual

Member Function Documentation

◆ connect()

void DiscordCPP::Discord::connect ( )
protected

◆ create_application_command()

DiscordCPP::ApplicationCommand DiscordCPP::Discord::create_application_command ( ApplicationCommand command)

creates a new application command

◆ get_application_commands() [1/2]

std::vector< DiscordCPP::ApplicationCommand > DiscordCPP::Discord::get_application_commands ( )

loads all application commands

Returns
a vector containing all global application commands

◆ get_application_commands() [2/2]

std::vector< DiscordCPP::ApplicationCommand > DiscordCPP::Discord::get_application_commands ( const Guild & guild)

loads all application commands for a guild

Parameters
[in]guildthe Guild to get the application commands for
Returns
a vector containing all application commands of the specified guild

◆ get_guild()

DiscordCPP::Guild * DiscordCPP::Discord::get_guild ( const std::string & guild_id)
protected

◆ get_shard()

std::shared_ptr< DiscordCPP::MainGateway > DiscordCPP::Discord::get_shard ( const unsigned int shard_id)
protected

◆ get_voice_state()

DiscordCPP::VoiceState * DiscordCPP::Discord::get_voice_state ( const std::string & user_id,
const std::string & guild_id )
protected

◆ handle_raw_event()

void DiscordCPP::Discord::handle_raw_event ( const std::string & event_name,
const json & data )
protected

◆ on_interaction()

void DiscordCPP::Discord::on_interaction ( Interaction interaction)
protectedvirtual

called when an interaction was created

Parameters
[in]interactionthe Interaction that was received

◆ on_message()

void DiscordCPP::Discord::on_message ( Message message)
protectedvirtual

called when a Message was received

Parameters
[in]messagethe Message that was received

◆ on_ready()

void DiscordCPP::Discord::on_ready ( User user)
protectedvirtual

called when successfully logged in

Parameters
[in]userthe User

◆ on_typing_start()

void DiscordCPP::Discord::on_typing_start ( User user,
TextChannel channel,
unsigned int timestamp )
protectedvirtual

called when a User starts typing

Parameters
[in]userthe User that started typing
[in]channelthe TextChannel where the USer started typing
[in]timestamp(unix time) when the User started typing

◆ on_user_ban()

void DiscordCPP::Discord::on_user_ban ( User user,
Guild guild )
protectedvirtual

called when a Member was banned

Parameters
[in]userthe User who has been banned
[in]guildthe Guild the User has been banned from

◆ on_user_join()

void DiscordCPP::Discord::on_user_join ( Member member,
Guild guild )
protectedvirtual

called when a User joins a Guild

Parameters
[in]memberthe User who has joined
[in]guildthe Guild the User has joined

◆ on_user_remove()

void DiscordCPP::Discord::on_user_remove ( User user,
Guild guild )
protectedvirtual

called when a User is removed from a Guild (leave/kick/ban)

Parameters
[in]userthe User who has been removed
[in]guildthe Guild the User has been removed from

◆ on_user_unban()

void DiscordCPP::Discord::on_user_unban ( User user,
Guild guild )
protectedvirtual

called when a Member was unbanned

Parameters
[in]userthe User who has been unbanned
[in]guildthe Guild the User has been unbanned from

◆ on_websocket_incoming_message()

void DiscordCPP::Discord::on_websocket_incoming_message ( const json & payload)
protected

◆ start()

void DiscordCPP::Discord::start ( )

Starts the bot. This will not block.

◆ update_presence()

void DiscordCPP::Discord::update_presence ( const std::string & status,
Activity activity = Activity(),
const bool afk = false,
const int shard_id = -1 )

updates the presence of user

Parameters
[in]statusthe new status (see DiscordStatus)
[in]activity(optional) the Activity
[in]afk(optional) wether the bot/user is afk or not
[in]shard_id(optional) the shard whose presence will be updated (use -1 for all shards, default is -1)

Friends And Related Symbol Documentation

◆ VoiceChannel::connect

std::shared_ptr< VoiceClient > VoiceChannel::connect ( )
friend

Member Data Documentation

◆ _application_id

std::string DiscordCPP::Discord::_application_id
protected

the bot's application id

◆ _gateways

std::vector<std::shared_ptr<MainGateway> > DiscordCPP::Discord::_gateways
protected

websocket clients

◆ _guilds

std::vector<Guild*> DiscordCPP::Discord::_guilds
protected

the guilds the user is a member

◆ _num_shards

unsigned int DiscordCPP::Discord::_num_shards
protected

number of shards

◆ _user

User* DiscordCPP::Discord::_user
protected

the user

◆ _voice_states

std::map<std::string, std::vector<VoiceState*> > DiscordCPP::Discord::_voice_states
protected

VoiceStates by user id.

◆ log

Logger DiscordCPP::Discord::log

The documentation for this class was generated from the following files: