如何从频道中删除用户

How to delete user from channel

尝试删除用户时,显示错误消息:

从对话中删除用户时出错:错误:StreamChat 错误代码 4:UpdateChannel 失败,错误为:"cannot add or remove members in a distinct channel, please create a new distinct channel with the desired members"

下面是删除用户的示例代码:

try {
      const response = await conversation.removeMembers(
        [user.id],
        { text: `${user.name} was removed from conversation`}
      );

      console.log('Response: ', response);

      console.log(`${user.name} was removed from conversation`);
    } catch (e) {
      console.log(`Error removing user from conversation: ${e}`);
    }

对话:

删除时,第一个请求 returns OK 状态与对话

我们运行也进入了这个问题。必须改变创建渠道的方式。文档很难找到,但在 this page 上它说 You cannot add/remove members for channels created this way.

意味着如果你想创建一个可以添加和删除成员的频道,你必须像 shown here 一样创建它,你可以在其中为频道分配一个你创建的唯一 ID(我们使用的是 UUID) .创建后,您可以向其中添加所需的成员……然后再添加或删除它们。