diff --git a/Lagrange.OneBot/Message/Entity/ReplySegment.cs b/Lagrange.OneBot/Message/Entity/ReplySegment.cs index 4bdc358cc..98f23daec 100644 --- a/Lagrange.OneBot/Message/Entity/ReplySegment.cs +++ b/Lagrange.OneBot/Message/Entity/ReplySegment.cs @@ -32,7 +32,6 @@ public override void Build(MessageBuilder builder, SegmentBase segment) public override SegmentBase FromEntity(MessageChain chain, IMessageEntity entity) { if (entity is not ForwardEntity forward || Database is null) throw new ArgumentException("The entity is not a forward entity."); - var collection = Database.GetCollection(); @@ -42,11 +41,10 @@ public override SegmentBase FromEntity(MessageChain chain, IMessageEntity entity var query = chain.IsGroup ? collection.Query().Where(x => x.Sequence == forward.Sequence).Where(x => x.GroupUin == groupUin) : collection.Query().Where(x => x.Sequence == forward.Sequence).Where(x => x.FriendUin == friendUin); - var target = query.First(); + var target = query.FirstOrDefault(); - return new ReplySegment - { - MessageId = target.MessageHash.ToString() - }; + return target == null + ? new ReplySegment { MessageId = 0.ToString() } + : new ReplySegment { MessageId = target.MessageHash.ToString() }; } } \ No newline at end of file