一个 Spigot/Paper 插件,为每个 Towny 城镇创建专属的私有 Discord 文本频道和角色。它使用 DiscordSRV 的关联账户数据,玩家的城镇成员身份将决定其 Discord 访问权限。

功能介绍
-
为每个 Towny 城镇创建对应的 Town: <城镇名称> 角色和 #town-<城镇名称> 频道。
-
限制每个频道仅对其城镇角色可见;@everyone 无法查看。
-
同步关联的 Towny 居民的角色,包括在玩家离开或迁移城镇后移除相应角色。
-
双向桥接 TownyChat 的 /tc 城镇聊天与各个城镇的 Discord 频道。
-
在城镇重命名后自动更新资源名称。
-
检测已删除的城镇,归档其频道,移除相关角色,并在配置的保留期结束后删除归档频道。
-
在启动后以及此后定期同步现有城镇信息,从而也能从遗漏的 Towny 变更或手动 Discord 编辑中恢复。
需求
- 运行 Java 25+ 的 Spigot/Paper 26.2+
- Towny Advanced 0.102.0.13+
- TownyChat
- DiscordSRV 1.30.5+,已配置并连接至你的 Discord 服务器
- 一个拥有 Manage Roles(管理角色)和 Manage Channels(管理频道)权限的 Discord 机器人角色,其位置需高于城镇所使用的角色
本插件基于 Spigot API 开发,兼容所有 Spigot/Paper 服务端。最新版的 Towny 要求使用 Paper、Purpur 或 Folia,而非原版 Spigot,因此请使用这些服务端实现之一以支持最新的 Towny 版本。
安装
下载插件后:
- 将插件 JAR 文件复制到服务器的
plugins/ 文件夹中。
- 启动服务器一次,然后编辑
plugins/TownyChatDiscord/config.yml。
- 将
guild-id 设置为你的 Discord 服务器的数字 ID。要获取该 ID,请在 用户设置 → 高级 中启用 Discord 的 开发者模式,然后右键点击你的服务器并选择 复制服务器 ID。可选:将 category-id 设置为 Discord 分类的数字 ID,以便将所有城镇频道放置在该分类下;同样通过右键点击分类并选择 复制频道 ID 来获取。
- 重启服务器或以操作员身份运行
/townychatdiscord reconcile。
配置
guild-id: "123456789012345678"
category-id: "234567890123456789" # 可选的分类 ID
role-prefix: "Town: "
channel-prefix: "town-"
sync-interval-seconds: 60
archive-deleted-towns: true
archive-days: 7 # 0 表示归档频道永久保留
town-chat-bridge:
enabled: true
townychat-channel-name: "town"
discord-to-minecraft-format: "&7[&bDiscord &7| &b%name%&7] &f%message%"
插件在单独的 towns.yml 文件的 towns: 下存储城镇 UUID 到 Discord 角色/频道 ID 的映射。除非你有意修复映射关系,否则请勿手动更改这些 ID。
城镇聊天桥接
TownyChat 的城镇频道通常名为 town 并由 /tc 命令使用。桥接功能会解析发言者所属的实际 Towny 城镇,因此 “Avalon” 城镇的 /tc 消息仅发送至 #town-avalon,反之亦然。Minecraft 到 Discord 的消息传递使用 DiscordSRV 的 webhook 发送工具,保留了通常的 DiscordSRV 玩家名称和头像样式。
Discord 端作者必须通过 DiscordSRV 进行链接,并且当前属于拥有该频道的城镇。来自 Discord 的消息默认发送给在线居民以及拥有 towny.chat.spy 权限的在线玩家。
请勿将动态创建的城镇频道 ID 添加到 DiscordSRV 的静态 Channels 映射中:此插件负责其路由管理。
操作
/townychatdiscord reconcile 会立即执行一次完整的 Towny 到 Discord 的数据同步。在修改配置或修复 Discord 资源后使用此命令非常有用。
Discord 角色变更是最终一致的:Discord 的 API 操作会被排队处理,正常的成员身份变更将在下一次协调(默认间隔为 60 秒)时生效。
A Spigot/Paper plugin that gives every Towny town its own private Discord text channel and Discord role. It uses DiscordSRV's linked-account data, so a player's town membership determines their Discord access.

What it does
- Creates a
Town: <town name> role and #town-<town name> channel for each Towny town.
- Restricts each channel to its town role;
@everyone cannot see it.
- Synchronizes roles for linked Towny residents, including removals after a player leaves or moves towns.
- Bridges TownyChat's
/tc town chat with each town's Discord channel in both directions.
- Renames resources after a town rename.
- Detects deleted towns, archives their channel, removes the role, and deletes the archived channel after the configured retention period.
- Reconciles existing towns after startup and periodically thereafter, so it also recovers from missed Towny changes or manual Discord edits.
Requirements
- Spigot/Paper 26.2+ running Java 25+
- Towny Advanced 0.102.0.13+
- TownyChat
- DiscordSRV 1.30.5+, configured and connected to your Discord server
- A Discord bot role with Manage Roles and Manage Channels, positioned above roles created for towns
The plugin targets the Spigot API and works on Spigot/Paper-compatible servers. The latest Towny releases require Paper, Purpur, or Folia rather than plain Spigot, so use one of those server implementations with the latest supported Towny stack.
Installation
Download the plugin, then:
- Copy the plugin JAR to the server's
plugins/ folder.
- Start the server once, then edit
plugins/TownyChatDiscord/config.yml.
- Set
guild-id to your Discord server's numeric ID. To get it, enable Developer Mode in Discord under User Settings → Advanced, then right-click your server and select Copy Server ID. Optionally set category-id to a Discord category's numeric ID to place all town channels inside that category; copy it the same way by right-clicking the category and selecting Copy Channel ID.
- Restart the server or run
/townychatdiscord reconcile as an operator.
Configuration
guild-id: "123456789012345678"
category-id: "234567890123456789" # optional category ID
role-prefix: "Town: "
channel-prefix: "town-"
sync-interval-seconds: 60
archive-deleted-towns: true
archive-days: 7 # 0 retains archived channels forever
town-chat-bridge:
enabled: true
townychat-channel-name: "town"
discord-to-minecraft-format: "&7[&bDiscord &7| &b%name%&7] &f%message%"
The plugin stores town UUID to Discord role/channel IDs under towns: in a separate towns.yml file. Do not manually change those IDs unless you are deliberately repairing a mapping.
Town chat bridge
TownyChat's town channel is normally named town and used by /tc. The bridge resolves the speaker's actual Towny town, so the "Avalon" town's /tc messages are sent only to #town-avalon and vice versa. Minecraft-to-Discord uses DiscordSRV's webhook delivery utility, retaining the usual DiscordSRV player name/avatar appearance.
Discord authors must be linked through DiscordSRV and currently belong to the town that owns the channel. Discord-originated messages are delivered to online residents and, by default, online players with towny.chat.spy.
Do not add dynamically-created town channel IDs to DiscordSRV's static Channels mapping: this plugin owns their routing.
Operations
/townychatdiscord reconcile immediately performs a full Towny-to-Discord synchronization. It is useful after changing configuration or repairing Discord resources.
Discord role changes are eventually consistent: Discord's API operations are queued, and normal membership changes are reflected on the next reconciliation (60 seconds by default).
评论 0
登录后参与评分
还没有评论,来抢沙发吧