Discord Integration (DI)

模组

· 作者 GeheimagentNr1

在 Discord 和 Minecraft 之间添加聊天链接,并提供通过 Discord 命令请求服务器数据的功能。

0 本站下载 0 关注 更新于 1 个月前

最新 26.3-4.0.5 · 26.3 · NeoForge

一键开服(送7天)

版本 4.X.X

有关该模组的旧版本,请查阅 wiki。

此模组将 Minecraft 聊天与 Discord 聊天连接起来。
该模组为 Dimension Access Manager 模组(CurseForge 或 Modrinth)和 More MobGriefing Options 模组(CurseForge 或 Modrinth)添加了 Discord 命令集成。
此模组仅在服务端运行,在客户端无法使用。


想要和朋友一起玩,需要一个服务器?但不知道如何搭建?直接租用一个已配置好的服务器吧!

点击上方的图片,选择一个套餐(建议至少 6 GB),
使用我的代码 agent 可享受首月 25% 的折扣,并与朋友们尽情游玩!


重要提示

  • 当分享安装了 Discord Integration 的服务器世界时,请务必删除 "serverconfig" 文件夹中的 "discordintegration-server.toml" 文件,以保护你的机器人令牌。
  • 你可以在 Discord 开发者网站 的“Bot”选项卡中重新生成机器人令牌。

支持

支持的版本图片
尚未发布该模组的 Minecraft 版本不受支持。
你可以在这里找到文本版本的支持列表。

功能

聊天

Minecraft > Discord

Minecraft 聊天中的所有消息都会通过 Discord 机器人发送到 Discord 聊天频道。
额外的死亡消息和进度提示消息也会发送到 Discord。
“say”和“me”命令已被修改,其发送的消息也会同步到 Discord。
服务器启动和停止的消息可以在配置文件中自定义。

Discord > Minecraft

除了来自机器人的消息外,所有消息都会发送到 Minecraft 聊天。
如果在配置中启用,机器人消息也可以发送到 Minecraft 聊天。
为了防止垃圾信息,可以从 Discord 传输到 Minecraft 的消息最大长度可以进行配置。如果消息过长,会在 Discord 聊天中显示错误消息。
作为命令的消息也不会发送到 Minecraft 聊天。
Discord Integration 默认添加了一些命令,自定义命令可以在配置中添加。命令前缀也可以在配置中进行设置。

管理

Discord Integration 的“管理”部分由两部分组成:管理频道和管理角色。
在所有 Discord Integration 命令都可以在管理频道中使用。此外,还会显示关于服务器启动、停止、崩溃以及玩家加入和离开的消息。如果启用了白名单功能,当 Minecraft 和 Discord 账号链接或取消链接,以及 Minecraft 账号被添加到或移除白名单时,会显示额外的消息。
此外,管理频道还可以用于 Minecraft 服务器的管理员和版主之间的对话,这些对话不会显示在 Minecraft 聊天中。
具有管理角色的用户可以使用标记为管理命令的命令来执行操作。

白名单

要使用 Discord Integration 的白名单功能,需要在 server.properties 文件中激活白名单。它有两种机制来确保白名单的安全:角色管理和单链接管理,将在以下部分中描述。当用户离开 Discord 服务器时,他们的链接会自动移除。如果链接不同步(例如因为 Minecraft 服务器离线或 Discord API 出现问题),可以通过重启服务器来解决,这将重新同步链接。
配置文件键 "whitelist.use_role" 用于设置是否启用角色机制,而配置文件键 "whitelist.use_single_linking_management" 用于设置是否启用单链接管理。
用户可以在聊天频道中使用 !link 和 !unlink 命令创建链接。重要提示:必须在配置中启用 !link 和 !unlink 命令后才能使用它们。

仅链接

如果两种机制都禁用,用户只需创建链接即可进入白名单。

角色

如果角色机制启用,用户必须拥有 ID 设置为配置文件键 "whitelist.role_id" 的角色。该角色必须由 Discord 服务器的版主分配。如果使用 "@everyone" 角色,用户只需创建一个链接即可进入白名单。

单链接管理

对于单链接管理,需要设置两个配置值。"whitelist.linking_management_channel_id" 需要设置为显示“链接消息”的频道的 ID。"whitelist.single_linking_management_role_id" 是用于激活或停用链接的角色 ID。可以通过点击消息下方的勾选或“X”反应来简单地激活或停用链接。
在启动时,链接管理频道中的所有链接消息都会更新,由于 Discord API 的限制,每条消息大约需要 1 秒。
示例链接管理消息

角色 + 单个链接管理

Discord 用户必须拥有分配的角色,其 ID 设置为配置变量 whitelist.role_id,并且该链接必须在链接管理频道中激活(详细信息见上一节)。

Minecraft 命令

  • /discord commands - 显示在 Discord Integration 中配置的可用命令列表及其帮助消息。
  • /discord gamerules - 显示所有 Minecraft 游戏规则的当前值。
  • /discord mods - 显示服务器上的所有模组列表。
  • /discord link <player> [<discordMemberId>] - 创建 Discord 用户与 Minecraft 玩家之间的链接。从 Discord 聊天中只能使用仅包含玩家名称的参数;在 Minecraft 中,只有同时提供玩家名称和 discordMemberId 时才能使用该命令(仅限 op 等级为 3 或更高的玩家)。
  • /discord unlink <player> [<discordMemberId>] - 删除 Discord 用户与 Minecraft 玩家之间的链接。从 Discord 聊天中只能使用仅包含玩家名称的参数;在 Minecraft 中,只有同时提供玩家名称和 discordMemberId 时才能使用该命令(仅限 op 等级为 3 或更高的玩家)。

默认 Discord 命令

如果在 Discord 聊天中输入以下命令,你将获得来自 Minecraft 服务器的信息。
可以在配置文件中添加自定义命令。

Vanilla Minecraft 命令

  • !difficulty - 显示服务器的难度设置。
  • !gamerules - 显示游戏规则及其值。
  • !help - 显示所有命令及其描述。
  • !link <Minecraft player name> - 将 Minecraft 玩家与此命令所在的 Discord 用户进行链接。
  • !mods - 显示服务器上模组的列表。
  • !online - 显示在线玩家的数量及具体名单。
  • !seed - 显示当前世界的种子。
  • !time - 显示服务器上的当前时间。
  • !tps - 显示服务器的 TPS 统计信息及其维度数据。
  • !unlink <Minecraft player name> - 通过此命令取消 Minecraft 玩家与该 Discord 用户的链接。

Dimension Access Manager 模组命令

  • !dimensions - 显示所有维度的访问状态。

More MobGriefing Options 模组命令

  • !mobgriefing - 显示所有生物相关的破坏选项。

服务器配置

配置文件位于“world”文件夹中的“serverconfig”文件夹内,文件名为 discordintegration-server.toml。世界文件夹的名称在 server.properties 文件中设置。

  • bot - 机器人常规配置

    • active - 是否启用 Discord 集成?默认值:false
    • bot_token - 你的 Discord 机器人的令牌。默认值:"INSERT BOT TOKEN HERE"
    • guild_id - Discord 服务器的 Guild/Server ID,Discord 集成将在其中运行。
    • discord_presence - Discord 状态(Presence)配置
      • show_discord_presence - 是否显示 Discord 状态消息?默认值:false
      • message - 在 Discord 状态中显示的消息(活动类型始终为“Playing”)。(可用参数:%online_player_count% = 在线玩家数量, %max_player_count% = 最大玩家数量) 默认值:"Minecraft with %online_player_count% players"
  • chat - 聊天频道设置

    • enabled - 是否链接 Minecraft 和 Discord 的聊天?默认值:false
    • channel_id - 将链接 Minecraft 和 Discord 聊道的频道 ID。
    • use_raw_message_format_discord_to_minecraft - 对于从 Discord 发送到 Minecraft 的消息,是否使用原始消息格式(示例:)?默认值:false
    • invalid_raw_message_format_for_discord_to_minecraft_error_message - 如果原始消息格式是无效的 JSON,则在 Discord 中显示的错误消息。(可用参数:%username% = Discord 用户名, %nickname% = Discord 昵称, %error_message% = 错误消息, %new_line% = 换行符) 默认值:"%username%%new_line%Error: Invalid JSON format for raw message for Discord to Minecraft message.%new_line%%error_message%"
    • message_format_discord_to_minecraft - 从 Discord 发送到 Minecraft 的消息格式。(可用参数:%username% = Discord 用户名, %nickname% = Discord 昵称, %message% = 消息内容) 默认值: "[%username%] %message%"
    • message_format_minecraft_to_discord - 从 Minecraft 发送到 Discord 的消息格式。(可用参数:%player% = 玩家名称, %message% = 消息内容) 默认值: "%player% %message%"
    • message_format_minecraft_to_discord_me_message - Minecraft /me 命令发送到 Discord 的消息格式。(可用参数:%player% = 玩家名称, %message% = 消息内容) 默认值: "%player% %message%"
    • max_char_count - 发送到 Minecraft 聊天的 Discord 消息最长允许多少个字符?如果值为 -1,则无长度限制。默认值:-1
    • max_char_count_error_message - 如果消息过长,则在 Discord 中显示的错误消息。(可用参数:%username% = Discord 用户名, %nickname% = Discord 昵称, %max_char_count% = 最大消息长度(chat.max_char_count 的值), %actual_message_char_count% = 发送消息的实际长度, %new_line% = 换行符) 默认值:"%username%%new_line%Error: Message too long.%new_line%Messages can only be up to %max_char_count% characters long.%new_line%Your message is %actual_message_char_count% characters long."
    • transmit_bot_messages - 是否将其他机器人的消息发送到 Minecraft 聊天?默认值:false
    • suppress_server_messages - 是否屏蔽从 Minecraft 服务器发送的消息(例如通过 say 命令发送的消息)?默认值:false
    • messages - 在聊天频道中 Discord 上显示的消息
      • server_started - 服务器启动消息选项(enabled: true, message: "Server started")
      • server_stopped - 服务器停止消息选项(enabled: true, message: "Server stopped")
      • server_crashed - 服务器崩溃消息选项(enabled: true, message: "Server crashed")
      • player_joined - 玩家加入消息选项(enabled: true, 包含 %player% 的消息)
      • player_left - 玩家离开消息选项(enabled: true, 包含 %player% 的消息)
      • player_died - 玩家死亡消息选项(enabled: true, 包含 %player%, %default_message% 的消息)
      • tamed_mob_died - 驯服生物死亡消息选项(enabled: true, 包含 %tamed_mob%, %default_message% 的消息)
      • player_got_advancement - 玩家获得进度消息选项(enabled: true, 包含 %player%, %advancement_title%, %advancement_description%, %new_line% 的消息)
  • management - 管理频道设置

    • enabled - 是否使用管理频道?默认值:false
    • channel_id - 管理频道所在的频道 ID。
    • role_id - Discord 用户执行管理命令所需的角色 ID。
    • messages - 在管理频道的 Discord 上显示的消息(server_started, server_stopped, server_crashed, player_joined, player_left, linking_created, linking_removed, whitelist_update_with_forced_message_update_start, whitelist_update_with_forced_message_update_finished, player_whitelist_added, player_whitelist_removed)
  • whitelist - 在 Discord 中管理白名单的设置

    • enabled - 是否启用 Discord 中的白名单管理?默认值:false
    • use_role - 用户是否需要拥有特定角色才能被列入白名单?默认值:true
    • role_id - 用户必须拥有的 Discord 角色 ID,以便被列入白名单。
    • use_single_linking_management - 在将 Minecraft 账户列入白名单之前,是否必须单独激活每个链接?默认值:true
    • single_linking_management_role_id - 用户必须拥有的 Discord 角色 ID,以便激活或停用链接。仅当 whitelist.use_single_linking_management 为 true 时需要。
    • linking_management_channel_id - 处理链接激活的频道 ID。
  • command_settings - 命令设置

    • command_prefix - Discord 命令的前缀。默认值:"!"
    • command_normal_user_permission_level - 没有管理角色的用户的 Minecraft 命令权限等级。默认值:2
    • command_management_user_permission_level - 拥有管理角色的用户的 Minecraft 命令权限等级。默认值:4
  • other_bots_command_prefixes - 其他机器人的命令前缀。带有这些前缀的消息不会发送到 Minecraft 聊天中。

    • messages - 命令消息设置(only_management_command_hint_message、link_created_result_message、link_already_exists_result_message、link_removed_result_message、link_invalid_discord_member_id_error_message、unknown_command_error_message、invalid_permissions_error_message)
    • commands - Discord 到 Minecraft 命令的映射(minecraft_command、discord_command、management_command、use_parameters、description、enabled)

如何设置 Discord 机器人并获取机器人令牌

首先,您需要登录 Discord 开发者网站。
点击“New Application”(新建应用程序)并为您的应用程序输入一个名称。
进入“Bot tab”(机器人选项卡)。
Discord Developer Page: Bot Tab
点击“Reset Token”(重置令牌)以在配置中获取机器人令牌。该令牌仅显示一次,因此请将其直接复制到配置文件中。

启用特权网关意图(Privileged Gateway Intents)

此步骤为必需。 在“Bot tab”(机器人选项卡)中,向下滚动至“Privileged Gateway Intents”(特权网关意图)并启用:

  • Server Members Intent(服务器成员意图)- 用于白名单、链接和管理角色
  • Message Content Intent(消息内容意图)- 用于读取 Discord 聊天中的消息和命令

点击“Save Changes”(保存更改)。
“Presence Intent”(在线状态意图)不需要启用。
如果未启用这些意图,机器人将无法连接到 Discord,并且服务器日志会显示带有“Disallowed intents”(不允许的意图)的错误(关闭代码 4014)。

要将机器人添加到服务器,请点击“General Information”(常规信息),并将“Client ID”(客户端 ID)添加到以下链接中:

您必须将 YOUR_BOTS_CLIENT_ID 替换为您机器人的客户端 ID。
Discord Developer Page: General Information Tab
打开此链接并将机器人添加到您拥有的某个服务器中。
机器人只能看到您允许的频道。 该链接故意不赋予机器人“View Channel”(查看频道)权限,因此它只能看到所有人(@everyone)可见的频道以及您明确允许的频道。如果某些频道并非对所有人可见,请在配置中设置的每个频道(聊天频道、管理频道、链接管理频道)中允许机器人(或其角色)“View Channel”(查看频道)权限:右键单击该频道 > “Edit Channel”(编辑频道)> “Permissions”(权限)。如果没有此权限,机器人将无法在这些频道中读取或发送消息。
您只能将机器人添加到您自己拥有的服务器中。如果您想将机器人添加到您不拥有的服务器中,则必须在“Bot tab”(机器人选项卡)中勾选“Public Bot”(公共机器人)选项,并由服务器所有者将其添加到其 Discord 服务器中。

如何获取公会 ID(Guild ID)

要获取公会 ID,您需要在 Discord 中进入“User Settings”(用户设置)>“Advanced”(高级),并激活“Developer Mode”(开发者模式)。
Discord Developer Mode
接下来,您进入机器人将要运行的服务器。
右键单击该服务器名称或图标,然后点击“Copy Server ID”(复制服务器 ID),并将其粘贴到配置文件中。
Discord Server Menu

如何获取频道 ID

要获取频道 ID,您需要在 Discord 中进入“User Settings”(用户设置)>“Advanced”(高级),并激活“Developer Mode”(开发者模式)。
Discord Developer Mode
接下来,您进入机器人将要运行的服务器和频道。
右键单击该频道,然后点击“Copy ID”(复制 ID),并将其粘贴到配置文件中。
Discord Channel Menu

如何获取角色 ID

要获取角色 ID,您需要在 Discord 中进入“User Settings”(用户设置)>“Advanced”(高级),并激活“Developer Mode”(开发者模式)。
Discord Developer Mode
接下来,您进入“Server Settings”(服务器设置)>“Roles”(角色)。
右键单击该角色,然后点击“Copy Role ID”(复制角色 ID),并将其粘贴到配置文件中。
Discord Role Menu


感谢 Muse31 提供的标志。
您可以在非商业整合包中使用此模组而无需事先询问。
您可以在 CurseForge 和 Modrinth 上找到我的更多模组。

This is a Forge mod only until 1.21.1. This is a NeoForge mod only starting 1.21.1. There will be no Fabric version. It will not be backported.

你是这个资源的作者?登录后可认领此资源。

评论 0

0.0
暂无评分
5 星
0
4 星
0
3 星
0
2 星
0
1 星
0
我的评分

登录后参与评分

还没有评论,来抢沙发吧

评论配图

相似资源