如何使用WTelegramClient将公开群组/超级群组转为私有?
使用WTelegramClient将公开群组/超级群组转为私有
针对超级群组(Supergroup)
超级群组的公开状态由公开用户名、邀请链接控制,执行以下两步即可转为私有:
- 移除公开用户名:调用
Channels_EditUsername方法,传入超级群组ID和空字符串作为新用户名// 替换为你的超级群组ID和access_hash var inputChannel = new InputChannel(supergroupId, supergroupAccessHash); await client.Channels_EditUsername(inputChannel, ""); - 关闭公开邀请链接:调用
Channels_ToggleInvite方法,关闭公开邀请权限await client.Channels_ToggleInvite(inputChannel, false);
(可选)若需彻底屏蔽搜索可发现性,可移除群组头像或修改简介说明状态。
针对普通群组(Group)
普通群组转为私有需限制成员邀请权限、移除公开链接:
- 设置仅管理员可邀请成员:调用
Messages_EditChatDefaultBannedRights,禁止普通用户发起邀请// 替换为你的普通群组ID var inputPeer = new InputPeerChat(groupId); await client.Messages_EditChatDefaultBannedRights(inputPeer, new ChatBannedRights { until_date = 0, invite_users = true // 禁止普通用户邀请他人,仅管理员可操作 }); - 删除所有公开邀请链接:先调用
Messages_GetExportedChatInvites获取所有链接,再逐个调用Messages_DeleteExportedChatInvite删除var invites = await client.Messages_GetExportedChatInvites(inputPeer, false); foreach (var invite in invites) if (invite is ExportedChatInvite exported) await client.Messages_DeleteExportedChatInvite(inputPeer, exported.link);
注意事项
- 操作账号必须是群组管理员,且拥有
change_info、invite_users权限 - 超级群组的
access_hash可通过client.GetChatAsync(supergroupId)获取群组信息后提取 - 建议先用测试群组验证操作,避免影响正式群组
内容的提问来源于stack exchange,提问作者Yahya Al-Nuaimi
相关产品推荐
相关产品推荐

