# 在 Discourse 上创建机器人

**URL:** https://meta.discourse.org/t/creating-bot-on-discourse/224822
**Category:** Development
**Created:** [2022年四月20日 07:52 UTC](https://meta.discourse.org/t/creating-bot-on-discourse/224822 "2022-04-20T07:52:10Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![Simon\_Manning](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon_manning/32/198596_2.png) [@Simon\_Manning](https://meta.discourse.org/u/Simon_Manning)
#### Post date: [2022年四月20日 13:42 UTC](https://meta.discourse.org/t/creating-bot-on-discourse/224822/3 "2022-04-20T13:42:19Z")

</div>

如果你真的想让它完全独立，你可以结合使用 webhook 将事件传递给你的机器人，以及 HTTP 请求 API 让你的机器人对 Discourse 进行更改。

> [@Configure webhooks that trigger on Discourse events to integrate with external services](https://meta.discourse.org/t/setting-up-webhooks/49045):
>
> A webhook is a way to notify external services about changes on the internet. It’s easier to setup, manage and develop than a Discourse plugin. Though, it does require you to program a little bit or understand its technical details. In this #howto, I’ll set up webhook to power a Github bot for referencing pull request brought in a forum. We’ll want to see a new comment on Github pull request when a new post has a link to it. It’s a very simple process: Publish a new post. A webhook event happ…

[Discourse API 文档](https://docs.discourse.org/)

正如 @merefield 所暗示的，可以创建不覆盖核心功能的插件，而是接收事件通知并与核心 API 交互，这样更容易维护，并且不太可能产生不必要的副作用。

采用 webhook/API 路线还需要设置一个堆栈来运行你的机器人，并确保它在 Discourse 可用的同时始终可用，这两者都可以通过加载到 Discourse 中的插件免费获得。

编写插件需要学习 Ruby 并熟悉 Discourse 类，但如果你已经能够用其他东西编写和维护机器人，我相信你可以很快学会所需的东西。

---

_[View the full topic](https://meta.discourse.org/t/creating-bot-on-discourse/224822)._
