This repository was archived by the owner on Dec 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.cpp
More file actions
58 lines (49 loc) · 1.29 KB
/
example.cpp
File metadata and controls
58 lines (49 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "ethyme.hpp"
#include <iostream>
#include "commands/channel.hpp"
#include "commands/greet.hpp"
#include "commands/guilds.hpp"
int main()
{
Ethyme::Logger::SetLogLevel(
(int)Logger::Level::Debug
| (int)Logger::Level::Infos
| (int)Logger::Level::Errors
);
try
{
Ethyme::Client client("Bot Token");
client.SetPrefix("!");
// Command example
client.AddCommand("channel", ChannelCommand);
client.AddCommand("greet", GreetCommand);
client.AddCommand("guilds", GuildsCommand);
// handler example
client.AddHandler(
Ethyme::EventType::MessageCreate,
[&](Ethyme::Events::Event& event) -> cppcoro::task<>
{
auto messageEvent = event.As<Ethyme::Events::MessageCreate>();
auto message = messageEvent.Message();
if (!message->Author()->Bot()
&& message->Content() == "!ping")
co_await message->Channel()->Send("pong hahaha");
},
"handler ID" // optional, random if not specified.
);
client.AddHandler(
Ethyme::EventType::Ready,
[&](Ethyme::Events::Event& event) -> cppcoro::task<>
{
auto readyEvent = event.As<Ethyme::Events::Ready>();
Logger::Info(std::string(*readyEvent.Client()->User()) + " is online!");
co_return;
}
);
client.Start();
}
catch (Ethyme::Exception e)
{
Ethyme::Logger::Error(e.what());
}
}