[GH-ISSUE #6385] [Feature]: Add feature Discord Bot #4331

Closed
opened 2026-10-31 20:38:53 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @omarsenusi on GitHub (Sep 1, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6385

Currently, the panel only supports Telegram notifications/bot settings. It would be helpful to have Discord bot support as well, as many communities and admins rely on Discord for notifications, alerts, and management.

Describe the solution you'd like

Add a new configuration section in the panel settings for Discord Bot:

Enable/Disable Discord Bot: Toggle switch.

Bot Token: Input field for the Discord bot token.

Admin/Channel ID: Input field for sending system alerts and client notifications directly to a specified Discord channel or admin user.

Commands Support: Basic commands similar to the Telegram bot (e.g., status, traffic usage, client status).

Alternatives you've considered

Using third-party webhooks or external custom scripts, but having built-in integration directly within the panel GUI would be much cleaner and more convenient for administrators.

Concrete use case

I manage a server community on Discord and prefer receiving system logs, bandwidth alerts, and server notifications directly in our admin Discord channels instead of using Telegram.

Mockups, screenshots, or examples

No response

Which parts of the panel would this affect?

No response

Are you willing to help?

  • I'd like to implement this feature myself and open a PR.
  • I can help test once a PR is open.

Before submitting

  • I searched existing issues and this feature has not been requested.
  • This feature request is written in English.
Originally created by @omarsenusi on GitHub (Sep 1, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6385 ### Is your feature request related to a problem? Currently, the panel only supports Telegram notifications/bot settings. It would be helpful to have Discord bot support as well, as many communities and admins rely on Discord for notifications, alerts, and management. ### Describe the solution you'd like Add a new configuration section in the panel settings for Discord Bot: Enable/Disable Discord Bot: Toggle switch. Bot Token: Input field for the Discord bot token. Admin/Channel ID: Input field for sending system alerts and client notifications directly to a specified Discord channel or admin user. Commands Support: Basic commands similar to the Telegram bot (e.g., status, traffic usage, client status). ### Alternatives you've considered Using third-party webhooks or external custom scripts, but having built-in integration directly within the panel GUI would be much cleaner and more convenient for administrators. ### Concrete use case I manage a server community on Discord and prefer receiving system logs, bandwidth alerts, and server notifications directly in our admin Discord channels instead of using Telegram. ### Mockups, screenshots, or examples _No response_ ### Which parts of the panel would this affect? _No response_ ### Are you willing to help? - [x] I'd like to implement this feature myself and open a PR. - [x] I can help test once a PR is open. ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this feature has not been requested. - [x] This feature request is written in English.
bsakaguchi 2026-10-31 20:38:53 +07:00
Author
Owner

@github-actions[bot] commented on GitHub (Sep 1, 2026):

Thanks — this is a valid feature request, not a bug: there is genuinely no Discord support anywhere in the panel today. A case-insensitive search for discord across the whole tree returns no matches, and the only two built-in notification channels are the Telegram bot (internal/web/service/tgbot/) and SMTP email (internal/web/service/email/). Leaving this open for a maintainer to decide on; I can't accept or schedule features.

One correction to the "I searched existing issues" box: the same request already exists as #2751 ("Discord Bot", opened 2025-03-10, labelled enhancement, closed 2025-03-11). Yours is far more specific, so I'm not closing this as a duplicate — but the earlier decision on #2751 is the relevant precedent, and I could not determine its close reason.

Since you offered to implement it

The good news is that the notification half already has a designed extension point. internal/eventbus/ is an in-process pub/sub, and docs/architecture.md §5.7 says outright:

Use it for cross-cutting notifications instead of importing notification services into producers.

The event types a Discord notifier would consume are fixed in internal/eventbus/events.go:10-25 — outbound.down|up, xray.crash, node.down|up, cpu.high, memory.high, login.attempt.

The email notifier is the smallest template to copy — internal/web/service/email/subscriber.go is 198 lines, and its whole contract is one method (line 33):

func (s *Subscriber) HandleEvent(e eventbus.Event) {
	if on, err := s.settingService.GetSmtpEnable(); err != nil || !on {
		return
	}

and it is wired in internal/web/web.go:632-633:

emailSub := email.NewSubscriber(s.settingService, emailService)
s.bus.Subscribe("email-notifier", emailSub.HandleEvent)

A "discord-notifier" would sit next to that and next to the "tg-notifier" subscriptions at internal/web/web.go:668 and :680.

The settings you described map onto the existing pattern in internal/web/service/setting.go — the defaults map already holds "tgBotEnable": "false" (line 74), "smtpEnable": "false" (line 168) and "smtpEnabledEvents": "login.attempt,cpu.high" (line 160), each with a getter/setter pair further down. On the UI side, frontend/src/pages/settings/TelegramTab.tsx and EmailTab.tsx are the shape a DiscordTab.tsx would follow.

Scope warning — the two halves are not the same size

Your request bundles two things with very different costs:

  1. Notifications / alerts — roughly the size of the email subscriber above, plus settings and one tab. Tractable.
  2. "Commands support similar to the Telegram bot" — the Telegram bot is 4,101 lines of non-test Go across 8 files (tgbot_router.go alone is 1,492; tgbot_client.go 782; tgbot.go 537). It also pulls a dependency: github.com/mymmrac/telego (tgbot.go:25). A Discord equivalent means a comparable library plus a second implementation of every command surface.

If you do open a PR, splitting it — notify-only first, commands later — is much more likely to be reviewable. CLAUDE.md also states a hard rule worth reading before you start: "Fix size must match bug size… If a fix genuinely needs new architecture, say so and get agreement first." Getting agreement on the approach before writing 4,000 lines is the point.

Four repo rules that will fail CI if missed:

  1. Any new g.POST/g.GET in internal/web/controller/ needs a matching entry in frontend/src/pages/api-docs/endpoints.ts — pinned both ways by TestRouteRegistryContract in internal/web/routes_contract_test.go.
  2. Any new struct crossing the API boundary must be added to StructAllow in tools/openapigen/main.go, or it is silently dropped from the schemas and build-openapi.mjs then fails.
  3. Every new English i18n key goes in all 13 locale JSON files under internal/web/translation/ and must be referenced in the same commit — frontend/src/test/i18n-dead-keys.test.ts fails both ways.
  4. Run make verify locally; it is the gate that mirrors most of CI.

Until something lands, the closest built-in option is enabling SMTP email alerts, which already fire on the same event set via smtpEnabledEvents.

Verdict: Feature request

This reply was generated automatically; a maintainer may follow up.

<!-- gh-comment-id:5493122304 --> @github-actions[bot] commented on GitHub (Sep 1, 2026): Thanks — this is a valid feature request, not a bug: there is genuinely no Discord support anywhere in the panel today. A case-insensitive search for `discord` across the whole tree returns no matches, and the only two built-in notification channels are the Telegram bot (`internal/web/service/tgbot/`) and SMTP email (`internal/web/service/email/`). Leaving this open for a maintainer to decide on; I can't accept or schedule features. One correction to the "I searched existing issues" box: the same request already exists as #2751 ("Discord Bot", opened 2025-03-10, labelled `enhancement`, closed 2025-03-11). Yours is far more specific, so I'm not closing this as a duplicate — but the earlier decision on #2751 is the relevant precedent, and I could not determine its close reason. ### Since you offered to implement it The good news is that the notification half already has a designed extension point. `internal/eventbus/` is an in-process pub/sub, and `docs/architecture.md` §5.7 says outright: > Use it for cross-cutting notifications instead of importing notification services into producers. The event types a Discord notifier would consume are fixed in `internal/eventbus/events.go:10-25` — `outbound.down|up`, `xray.crash`, `node.down|up`, `cpu.high`, `memory.high`, `login.attempt`. The email notifier is the smallest template to copy — `internal/web/service/email/subscriber.go` is 198 lines, and its whole contract is one method (line 33): ```go func (s *Subscriber) HandleEvent(e eventbus.Event) { if on, err := s.settingService.GetSmtpEnable(); err != nil || !on { return } ``` and it is wired in `internal/web/web.go:632-633`: ```go emailSub := email.NewSubscriber(s.settingService, emailService) s.bus.Subscribe("email-notifier", emailSub.HandleEvent) ``` A `"discord-notifier"` would sit next to that and next to the `"tg-notifier"` subscriptions at `internal/web/web.go:668` and `:680`. The settings you described map onto the existing pattern in `internal/web/service/setting.go` — the defaults map already holds `"tgBotEnable": "false"` (line 74), `"smtpEnable": "false"` (line 168) and `"smtpEnabledEvents": "login.attempt,cpu.high"` (line 160), each with a getter/setter pair further down. On the UI side, `frontend/src/pages/settings/TelegramTab.tsx` and `EmailTab.tsx` are the shape a `DiscordTab.tsx` would follow. ### Scope warning — the two halves are not the same size Your request bundles two things with very different costs: 1. **Notifications / alerts** — roughly the size of the email subscriber above, plus settings and one tab. Tractable. 2. **"Commands support similar to the Telegram bot"** — the Telegram bot is **4,101 lines of non-test Go across 8 files** (`tgbot_router.go` alone is 1,492; `tgbot_client.go` 782; `tgbot.go` 537). It also pulls a dependency: `github.com/mymmrac/telego` (`tgbot.go:25`). A Discord equivalent means a comparable library plus a second implementation of every command surface. If you do open a PR, splitting it — notify-only first, commands later — is much more likely to be reviewable. `CLAUDE.md` also states a hard rule worth reading before you start: *"Fix size must match bug size… If a fix genuinely needs new architecture, say so and get agreement first."* Getting agreement on the approach before writing 4,000 lines is the point. Four repo rules that will fail CI if missed: 1. Any new `g.POST`/`g.GET` in `internal/web/controller/` needs a matching entry in `frontend/src/pages/api-docs/endpoints.ts` — pinned both ways by `TestRouteRegistryContract` in `internal/web/routes_contract_test.go`. 2. Any new struct crossing the API boundary must be added to `StructAllow` in `tools/openapigen/main.go`, or it is silently dropped from the schemas and `build-openapi.mjs` then fails. 3. Every new English i18n key goes in all **13** locale JSON files under `internal/web/translation/` *and* must be referenced in the same commit — `frontend/src/test/i18n-dead-keys.test.ts` fails both ways. 4. Run `make verify` locally; it is the gate that mirrors most of CI. Until something lands, the closest built-in option is enabling SMTP email alerts, which already fire on the same event set via `smtpEnabledEvents`. Verdict: Feature request *This reply was generated automatically; a maintainer may follow up.* <!-- claude-issue:analyst -->
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#4331
No description provided.