Skip to content

关于持续会话 #122

Answered by ForteScarlet
88Fanchen asked this question in Q&A
Apr 12, 2023 · 1 comments · 1 reply
Discussion options

You must be logged in to vote
    /**
     * 监听好友消息:
     * <p>
     * 好友发送:改名字
     * bot:改什么名字?(1分钟限时)
     * 好友:xxx(名字)
     * bot:更改成功!
     */
    @Listener
    @Filter("改名字")
    public void demo(FriendMessageEvent event, ContinuousSessionContext context) {
        event.replyBlocking("改什么名字?");
        MessageContent nextMessage;
        try {
            // 等待并获取下一个类型为 FriendMessageEvent 的消息事件中的消息,
            // 且使用当前 event 作为基础过滤条件(目标用户的ID等基础信息),
            // 并且限时一分钟,否则抛出 TimeoutCancellationException 异常
            nextMessage = context.nextMessage(event, FriendMessageEvent.Key, Duration.ofMinutes(1));
        } catch (TimeoutCancellationException timeout) {
            // 超时
            event.replyBlocking(

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@88Fanchen
Comment options

Answer selected by 88Fanchen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
组件:mirai 与mirai组件有关的内容
2 participants