# 用户个人资料页面上的“消息”和“聊天”按钮

**URL:** <https://meta.discourse.org/t/message-and-chat-buttons-on-users-own-profile-page/379978>\
**Category:** UX\
**Tags:** fixed\
**Created:** [2025年八月23日 04:58 UTC](https://meta.discourse.org/t/message-and-chat-buttons-on-users-own-profile-page/379978 "2025-08-23T04:58:26Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![NateDhaliwal](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/natedhaliwal/32/313494_2.png) [@NateDhaliwal](https://meta.discourse.org/u/NateDhaliwal)\
**Post date:** [2025年八月24日 14:00 UTC](https://meta.discourse.org/t/message-and-chat-buttons-on-users-own-profile-page/379978/7 "2025-08-24T14:00:35Z")

</div>

@donaldsoncd 尝试将这段代码添加到 JS 选项卡。它只会隐藏您用户页面上的按钮。按钮仍然显示在用户卡片上。

```js
import { apiInitializer } from "discourse/lib/api";

export default apiInitializer((api) => {
  api.onPageChange((url, title) => {
      if (url.startsWith("/u/natedhaliwal")) {
          const pmBtn = document.querySelector("button.compose-pm");
          pmBtn.style.display = "none";
          const chatBtn = document.querySelector("li.user-card-below-message-button.chat-button");
          if (chatBtn.parentNode.className != "usercard-controls") {
              chatBtn.style.display = "none";
          }
      }
  });
});

```

这有点取巧，但能完成工作。  
您可以将 `/u/natedhaliwal` 部分替换为 `/u/<username>`。

* * *

如果您想完全移除任何人与您私信或聊天功能，您需要：

1. 前往 `discourse.example.com/my/preferences/users`。
2. 取消勾选复选框 `允许其他用户向我发送个人消息和聊天直接消息`。

* * *

希望以上信息对您有帮助！

---

_[View the full topic](https://meta.discourse.org/t/message-and-chat-buttons-on-users-own-profile-page/379978)._
