diff --git a/utils/wechat/contact_manager.py b/utils/wechat/contact_manager.py index 5036e73..d58053e 100644 --- a/utils/wechat/contact_manager.py +++ b/utils/wechat/contact_manager.py @@ -95,6 +95,9 @@ class ContactManager: # 判断是否为群组(wxid以@chatroom结尾) elif wxid.endswith('@chatroom'): self._group_contacts[wxid] = nickname + # 确保群ID在字典中存在 + if wxid not in self._group_contacts_friends: + self._group_contacts_friends[wxid] = {} # 获取群成员信息: for friend in self._group_members: if friend.get('chatroom_id') == wxid: @@ -241,7 +244,10 @@ class ContactManager: self._official_accounts[wxid] = nickname elif wxid.endswith('@chatroom'): self._group_contacts[wxid] = nickname - # 需要获取群成员昵称信息; 从数据库里面提取。 + # 确保群ID在字典中存在 + if wxid not in self._group_contacts_friends: + self._group_contacts_friends[wxid] = {} + # 获取群成员信息: for friend in self._group_members: if friend.get('chatroom_id') == wxid: self._group_contacts_friends[wxid].update(