Skip to content
This repository was archived by the owner on Aug 16, 2024. It is now read-only.

Commit cf00833

Browse files
committed
新增: 语音消息示例;
1 parent fd46e84 commit cf00833

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

examples/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ api_exe(GroupMemberInfo)
3434
api_exe(GroupNameChange)
3535
api_exe(GroupConfig)
3636
api_exe(MemberCardChange)
37-
api_exe(Command)
37+
api_exe(Command)
38+
api_exe(VoiceMessage)

examples/VoiceMessage.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <iostream>
2+
// 使用静态库必须要在引入 mirai.h 前定义这个宏
3+
#define MIRAICPP_STATICLIB
4+
#include <mirai.h>
5+
6+
int main()
7+
{
8+
using namespace std;
9+
using namespace Cyan;
10+
system("chcp 65001");
11+
MiraiBot bot("127.0.0.1", 539);
12+
while (true)
13+
{
14+
try
15+
{
16+
bot.Auth("INITKEY7A3O1a9v", 1589588851_qq);
17+
break;
18+
}
19+
catch (const std::exception& ex)
20+
{
21+
cout << ex.what() << endl;
22+
}
23+
MiraiBot::SleepSeconds(1);
24+
}
25+
cout << "成功登录 bot。" << endl;
26+
27+
bot.On<GroupMessage>(
28+
[&](GroupMessage m)
29+
{
30+
MiraiVoice voice;
31+
voice.Id = "BDD8FD5EAF989C4F4B7DB4D853A9509E.amr";
32+
m.Reply(MessageChain().Voice(voice));
33+
});
34+
35+
36+
bot.EventLoop();
37+
38+
return 0;
39+
}

0 commit comments

Comments
 (0)