好友 OneBotFriend
OneBotFriend 实现 Contact, OneBotStrangerAware 和其他一些功能接口(后续 "更多能力" 中会介绍), 用于表示一个 OneBot11 协议中的 好友。
Contact
OneBotFriend 实现来自 Contact 定义的抽象属性或函数。
- id
QQ号。
- avatar
成员QQ头像。
- name
用户名。
SendSupport
OneBotFriend 拥有发送消息的能力。 使用 send 发送纯文本、消息或转发事件消息体。
val friend: OneBotFriend = ...
friend.send("text")
friend.send("text".toText() + Face(123.ID))
friend.send(messageContent)
OneBotFriend friend = ...;
friend.sendAsync("text");
friend.sendAsync(
Messages.builder()
.add("text")
.add(new Face(Identifies.of(123)))
.build()
);
friend.sendAsync(messageContent);
OneBotFriend friend = ...;
friend.sendBlocking("text");
friend.sendBlocking(
Messages.builder()
.add("text")
.add(new Face(Identifies.of(123)))
.build()
);
friend.sendBlocking(messageContent);
OneBotFriend friend = ...;
Mono.from(friend.sendReactive("text"))
.subscribe();
Mono.from(friend.sendReactive(
Messages.builder()
.add("text")
.add(new Face(Identifies.of(123)))
.build()
))
.subscribe();
Mono.from(friend.sendReactive(messageContent))
.subscribe();
OneBotStrangerAware
OneBotFriend 实现 OneBotStrangerAware, 可以通过 toStranger 查询并得到一个对应的 OneBotStranger 类型。
val friend: OneBotFriend = ...
val stranger = friend.toStranger()
OneBotFriend friend = ...;
friend.toStrangerAsync()
.thenAccept(stranger -> {
// ...
});
OneBotFriend friend = ...;
var stranger = friend.toStrangerBlocking();
OneBotFriend friend = ...;
Mono.from(friend.toStrangerReactive())
.subscribe(stranger -> {
// ...
});
更多能力
SendLikeSupport
OneBotFriend 实现 SendLikeSupport 接口, 支持使用 sendLike(Int) 来点赞用户。
参数代表次数,一般来说一人一天最多共计10次赞, 但是代码内无校验,交给OneBot服务端处理。
val friend: OneBotFriend = ...
friend.sendLike(5)
OneBotFriend friend = ...;
friend.sendLikeAsync(5);
OneBotFriend friend = ...;
friend.sendLikeBlocking(5);
OneBotFriend friend = ...;
Mono.from(friend.sendLikeReactive(5))
.subscribe();
获取 OneBotFriend
好友 OneBotFriend 通常来自 OneBotBot 或与好友相关的事件。
来自事件
大多数跟好友相关的事件中都可以直接获取到 OneBotFriend。 通常来讲,如果事件主体与好友相关,那么就是 content, 如果侧面相关,例如某个好友消息事件中, 消息才是重点,而好友则为 author。
07 November 2026