> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# chat_manager::add_local_user

> chat_manager::add_local_user

# chat\_manager::add\_local\_user

將本機使用者新增至本機 chat\_manager 執行個體。

## 語法

```cpp theme={null}
chat_user* add_local_user(  
    PCWSTR xboxUserId  
)  
```

### 參數

*xboxUserId*   \_In\_\
類型：PCWSTR

要新增之本機使用者的 XBOX 使用者識別碼。

### 傳回值

類型：chat\_user\*

## 備註

新增至 Game Chat 2 執行個體的所有本機使用者，都必須先使用 [XUserAddAsync](/zh-TW/reference/system/xuser/functions/xuseraddasync) 新增。

除非本機與遠端使用者的總數等於在 chat\_manager::initialize() 中指定的最大使用者數目，否則使用者會無條件新增。

傳回值是指向與此使用者相關聯之 chat\_user 物件的指標。如果 XBOX 使用者識別碼無效，使用者的 chat\_indicator 值將會是 game\_chat\_user\_chat\_indicator::platform\_restricted。

典型的模式如下：

```cpp theme={null}
chat_user* newLocalChatUser = chat_manager::singleton_instance().add_local_user(&amp;lt;local_user_xuid&amp;gt;);

size_t chatUserCount; 
chat_user_array chatUsers; 
chat_manager::singleton_instance().get_remote_chat_users(&chatUserCount, &chatUsers); 
for (uint32_t chatUserIndex = 0; chatUserIndex < chatUsercount; ++chatUserIndex) 
{ 
    chat_user* chatUser = chatUsers[chatUserIndex]; 
    game_chat_communication_relationship_flags relationship = game_chat_communication_relationship_flags::none; 
    if (chatUser can send and receive to/from newLocalChatUser) 
    { 
        relationship = c_communicationRelationshipSendAndReceiveAll; 
    } 
    else if (chatUser can send to newLocalChatUser) 
    { 
        relationship = c_communicationRelationshipSendAll; 
    } 
    else if (chatUser can receive from newLocalChatUser) 
    { 
        relationship = c_communicationRelationshipReceiveAll; 
    } 

    newLocalChatUser->set_communication_relationship(chatUser, relationship); 
} 
```

## 需求

**標頭：** GameChat2.h

**支援的平台：** Windows、XBOX One 系列主機和 XBOX Series 主機

## 另請參閱

[chat\_manager](/zh-TW/reference/chat/gamechat2/classes/chat_manager/chat_manager)\
[chat\_user](/zh-TW/reference/chat/gamechat2/classes/chat_user/chat_user)\
[chat\_manager::add\_remote\_user](/zh-TW/reference/chat/gamechat2/classes/chat_manager/methods/chat_manager_add_remote_user)\
[chat\_manager::remove\_user](/zh-TW/reference/chat/gamechat2/classes/chat_manager/methods/chat_manager_remove_user)


## Related topics

- [chat_manager::get_chat_users](/zh-TW/reference/chat/gamechat2/classes/chat_manager/methods/chat_manager_get_chat_users.md)
- [使用 Game Chat 2 C++ API](/zh-TW/services/xbox-services/multiplayer/chat/game-chat2/using-game-chat-2.md)
- [chat_manager::add_remote_user](/zh-TW/reference/chat/gamechat2/classes/chat_manager/methods/chat_manager_add_remote_user.md)
- [chat_manager::remove_user](/zh-TW/reference/chat/gamechat2/classes/chat_manager/methods/chat_manager_remove_user.md)
- [chat_user::local](/zh-TW/reference/chat/gamechat2/classes/chat_user/methods/chat_user_local_function_2.md)
