Skip to content

任何消息都有[mirai:source]的码,请问这是什么功能 #706

Answered by Karlatemp
Alceatraz asked this question in Q&A
Discussion options

You must be logged in to vote

这是 MessageSource, 存放该信息来源, 若只需要信息内容, 请参考以下代码

// kotlin

// message: MessageChain
val msg = message.filterIsInstance<MessageContent>()
// java
@SuppressWarnings({"rawtypes", "unchecked"})
private static List<MessageContent> content(MessageChain msg) {
  return (List) msg.stream()
            .filter(it -> it instanceof MessageContent)
            .collect(Collectors.toList());
}

另注: size() = 2 时也不一定是一条信息, 可能还会存在 QuoteReply(回复信息)

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

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

Answer selected by Him188
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #706 on December 24, 2020 10:47.