Skip to content

Discord 凭据#

¥Discord credentials

你可以使用以下凭据验证以下节点:

¥You can use these credentials to authenticate the following nodes:

先决条件#

¥Prerequisites

¥Create a Discord account.

  • 对于 Bot 和 OAuth2 凭证:

¥For Bot and OAuth2 credentials:

¥For webhook credentials, create a webhook.

支持的身份验证方法#

¥Supported authentication methods

  • 机器人

¥Bot

  • OAuth2

  • Webhook

不确定要使用哪种方法?请参阅 选择身份验证方法 获取更多指导。

¥Not sure which method to use? Refer to Choose an authentication method for more guidance.

相关资源#

¥Related resources

有关服务的更多信息,请参阅 Discord 开发者文档

¥Refer to Discord's Developer documentation for more information about the service.

使用机器人#

¥Using bot

如果你想使用机器人令牌而不是 OAuth2 将机器人添加到你的 Discord 服务器,请使用此方法。

¥Use this method if you want to add the bot to your Discord server using a bot token rather than OAuth2.

要配置此凭据,你需要:

¥To configure this credential, you'll need:

  • 机器人令牌:创建包含机器人的应用后生成。

¥A Bot Token: Generated once you create an application with a bot.

创建包含机器人的应用并生成机器人令牌:

¥To create an application with a bot and generate the Bot Token:

  1. 如果你还没有应用,请在 开发者门户 中创建一个应用。

¥If you don't have one already, create an app in the developer portal. 2. 输入应用名称。

¥Enter a Name for your app. 3. 选择“创建”。

¥Select Create. 4. 从左侧菜单中选择“机器人”。

¥Select Bot from the left menu. 5. 在“令牌”下,选择“重置令牌”以生成新的机器人令牌。

¥Under Token, select Reset Token to generate a new bot token. 6. 复制令牌并将其添加到你的 n8n 凭证中。

¥Copy the token and add it to your n8n credential. 7. 在“机器人”>“特权网关意图”中,添加你希望机器人拥有的任何特权意图。有关特权意图的更多信息,请参阅 配置你的机器人

¥In Bot > Privileged Gateway Intents, add any privileged intents you want your bot to have. Refer to Configuring your bot for more information on privileged intents.

  • n8n 建议启用 SERVER MEMBERS INTENT:你的机器人需要接收 GUILD_MEMBERS 下列出的事件。

    ¥n8n recommends activating SERVER MEMBERS INTENT: Required for your bot to receive events listed under GUILD_MEMBERS. 8. 在“安装”>“安装上下文”中,选择你希望机器人使用的安装上下文:

¥In Installation > Installation Contexts, select the installation contexts you want your bot to use:

  • 选择“服务器端安装”以安装服务器端应用。(n8n 用户最常用。)

    ¥Select Guild Install for server-installed apps. (Most common for n8n users.)

  • 选择“用户安装”以启用用户安装的应用。(n8n 用户较少使用,但可能对测试有用。)

    ¥Select User Install for user-installed apps. (Less common for n8n users, but may be useful for testing.)

  • 有关这些安装上下文的更多信息,请参阅 Discord 的 选择安装上下文 文档。

    ¥Refer to Discord's Choosing installation contexts documentation for more information about these installation contexts. 9. 在“安装”>“安装链接”中,如果尚未选择,请选择“Discord 提供的链接”。

¥In Installation > Install Link, select Discord Provided Link if it's not already selected. 10. 仍在安装页面,在“默认安装设置”部分,选择 applications.commandsbot 范围。有关这些和其他作用域的更多信息,请参阅 Discord 的 作用域 文档。

1
¥Still on the **Installation** page, in the **Default Install Settings** section, select `applications.commands` and `bot` scopes. Refer to Discord's [Scopes](https://discord.com/developers/docs/topics/oauth2#shared-resources-oauth2-scopes) documentation for more information about these and other scopes.
  1. 在“机器人 > 机器人权限”页面添加权限。有关更多信息,请参阅 Discord 的 权限 文档。n8n 建议你为 Discord 节点选择以下权限:

    ¥Add permissions on the Bot > Bot Permissions page. Refer to Discord's Permissions documentation for more information. n8n recommends selecting these permissions for the Discord node:

    • 管理角色

    ¥Manage Roles

    • 管理通道

    ¥Manage Channels

    • 读取消息/查看通道

    ¥Read Messages/View Channels

    • 发送消息

    ¥Send Messages

    • 创建公共线程

    ¥Create Public Threads

    • 创建私有线程

    ¥Create Private Threads

    • 以线程形式发送消息

    ¥Send Messages in Threads

    • 发送文本转语音消息

    ¥Send TTS Messages

    • 管理消息

    ¥Manage Messages

    • 管理主题

    ¥Manage Threads

    • 嵌入链接

    ¥Embed Links

    • 附加文件

    ¥Attach Files

    • 读取消息历史记录

    ¥Read Message History

    • 添加反应

    ¥Add Reactions 12. 将应用添加到你的服务器或测试服务器:

    ¥Add the app to your server or test server: 1. 前往“安装”>“安装链接”并复制其中列出的链接。

    ¥Go to Installation > Install Link and copy the link listed there. 2. 将链接粘贴到浏览器中并按 Enter 键。

    ¥Paste the link in your browser and hit Enter. 3. 在安装提示中选择“添加到服务器”。

    ¥Select Add to server in the installation prompt. 4. 应用添加到服务器后,你将在成员列表中看到它。

    ¥Once your app's added to your server, you'll see it in the member list.

以下步骤概述了设置 n8n 凭证所需的基本功能。请参阅 Discord 创建应用 指南,了解有关创建应用的更多信息,尤其:

¥These steps outline the basic functionality needed to set up your n8n credential. Refer to the Discord Creating an App guide for more information on creating an app, especially:

¥Fetching your credentials for getting your app's credentials into your local developer environment.

  • 有关设置用于交互式 /slash 命令的公共端点的信息,请参阅 交互处理

¥Handling interactivity for information on setting up public endpoints for interactive /slash commands.

使用 OAuth2#

¥Using OAuth2

如果你想使用 OAuth2 流程将机器人添加到 Discord 服务器,请使用此方法,这可以简化用户安装你的应用的过程。

¥Use this method if you want to add the bot to Discord servers using the OAuth2 flow, which simplifies the process for those installing your app.

要配置此凭据,你需要:

¥To configure this credential, you'll need:

  • 客户端 ID

¥A Client ID

  • 客户端密钥:

¥A Client Secret

  • 选择是否在标头或正文中发送身份验证信息。

¥Choose whether to send Authentication in the Header or Body

  • 机器人令牌:

¥A Bot Token

有关使用机器人创建应用并生成令牌的详情,请按照上述 使用机器人 中的相同步骤操作。

¥For details on creating an application with a bot and generating the token, follow the same steps as in Using bot above.

然后:

¥Then:

  1. 复制机器人用户 OAuth 令牌,并将其作为访问令牌输入到你的 n8n 凭据中。

¥Copy the Bot Token you generate and add it into the n8n credential. 2. 在 Discord 应用中打开 OAuth2 页面,访问你的客户端 ID 并生成客户端密钥。将以下内容添加到你的 n8n 凭据中。

¥Open the OAuth2 page in your Discord application to access your Client ID and generate a Client Secret. Add these to your n8n credential. 3. 从 n8n 复制 OAuth 重定向 URL,并将其添加到 Discord 应用的 OAuth2 > 重定向中。务必保存这些更改。

¥From n8n, copy the OAuth Redirect URL and add it into the Discord application in OAuth2 > Redirects. Be sure you save these changes.

使用 Webhook#

¥Using webhook

要配置此凭据,你需要:

¥To configure this credential, you'll need:

  • Webhook URL:创建 Webhook 后生成。

¥A Webhook URL: Generated once you create a webhook.

要获取 Webhook URL,请创建一个 Webhook 并复制生成的 URL:

¥To get a Webhook URL, you create a webhook and copy the URL that gets generated:

  1. 打开你的 Discord 服务器设置,然后打开“集成”选项卡。

¥Open your Discord Server Settings and open the Integrations tab. 2. 选择“创建 Webhook”以创建新的 Webhook。

¥Select Create Webhook to create a new webhook. 3. 为你的 webhook 命名,使其具有意义。

¥Give your webhook a Name that makes sense. 4. 选择名称旁边的头像以编辑或上传新头像。

¥Select the avatar next to the Name to edit or upload a new avatar. 5. 在“通道”下拉菜单中,选择 Webhook 应发布到的通道。

¥In the CHANNEL dropdown, select the channel the webhook should post to. 6. 选择“复制 Webhook URL”以复制 Webhook URL。将此 URL 输入到你的 n8n 凭据中。

¥Select Copy Webhook URL to copy the Webhook URL. Enter this URL in your n8n credential.

更多信息,请参阅 Discord 创建 Webhook 文档

¥Refer to the Discord Making a Webhook documentation for more information.

选择身份验证方法#

¥Choose an authentication method

最简单的安装方式是使用 Webhook。在 Discord 服务器上创建 Webhook 并将其添加到单个通道。Webhook 可以向通道发布消息。它们不需要机器人用户或身份验证。但它们无法监听或响应用户请求或命令。如果你需要一种无需交互或反馈即可向通道发送消息的简单方法,请使用 Webhook。

¥The simplest installation is a webhook. You create and add webhooks to a single channel on a Discord server. Webhooks can post messages to a channel. They don't require a bot user or authentication. But they can't listen or respond to user requests or commands. If you need a straightforward way to send messages to a channel without the need for interaction or feedback, use a webhook.

机器人是比 Webhook 更高级的交互式组件。你可以将机器人添加到 Discord 服务器(在 Discord API 文档中称为 guild)或用户账户。添加到服务器的机器人可以与服务器所有通道上的用户进行交互。它们可以管理通道、发送和接收消息、检索所有用户列表以及更改用户角色。如果你需要构建交互式、复杂或多步骤的工作流,请使用机器人。

¥A bot is an interactive step up from a webhook. You add bots to the Discord server (referred to as a guild in the Discord API documentation) or to user accounts. Bots added to the server can interact with users on all the server's channels. They can manage channels, send and retrieve messages, retrieve the list of all users, and change their roles. If you need to build an interactive, complex, or multi-step workflow, use a bot.

OAuth2 本质上是一个使用 OAuth2 流程而非仅使用机器人令牌的机器人。与机器人一样,你可以将这些节点添加到 Discord 服务器或用户账户。这些凭证提供与机器人相同的功能,但可以简化机器人在服务器上的安装。

¥OAuth2 is basically a bot that uses an OAuth2 flow rather than just the bot token. As with bots, you add these to the Discord server or to user accounts. These credentials offer the same functionalities as bots, but they can simplify the installation of the bot on your server.