@koishijs/plugin-adapter-discord
接入方法
- 前往 https://discord.com/developers/applications,登录账号创建一个应用
- 点击「Bot」并创建一个新的机器人,保存这个页面中的 token(请注意不要泄露)
- To invite your bot into your server, click "OAuth2" and check the permissions that required for your bot in URL Generator, make sure "Bot" to be checked.
- Open the link that you generated above, select the server that you have the admin permissions, then you could add your bot into the server successfully.
- 将上面的 token 作为机器人配置项即可使用
配置项
包括全部的 WsClient
选项和下列额外选项:
options.token
- 类型:
string
机器人账户的令牌。
options.endpoint
- 类型:
string
- 默认值:
'https://discord.com/api/v8'
要连接的服务器地址。
options.proxyAgent
- 类型:
string
- 默认值:
app.config.request.proxyAgent
请求时默认使用的网络代理。
options.gateway
- 类型:
string
- 默认值:
'wss://gateway.discord.gg/?v=8&encoding=json'
要连接的 WebSocket 网关。
options.intents
- 类型:
number
- 默认值:
GUILD_MESSAGES | GUILD_MESSAGE_REACTIONS | DIRECT_MESSAGES | DIRECT_MESSAGE_REACTIONS
需要订阅的机器人事件。这是一个以 bitset 形式表达的正整数,每一位代表一类事件。
options.handleExternalAsset
- 可选值:
string
- 默认值:
'auto'
指定单独发送外链资源时采用的方法:
- download: 先下载后发送
- direct: 直接发送链接
- auto: 发送一个 HEAD 请求,如果返回的 Content-Type 正确,则直接发送链接,否则先下载后发送
options.handleMixedContent
- 可选值:
string
- 默认值:
'auto'
指定发送图文混合内容时采用的方法:
- separate: 将每个不同形式的内容分开发送
- attach: 图片前如果有文本内容,则将文本作为图片的附带信息进行发送
- auto: 如果图片本身采用直接发送则与前面的文本分开,否则将文本作为图片的附带信息发送
当配置为 attach
并且发送文本+图片形式的消息时,无论 handleExternalAsset
配置为何都会先下载后发送。
内部 API
internal.addGuildMember()
internal.addGuildMemberRole()
internal.addThreadMember()
internal.beginGuildPrune()
internal.bulkDeleteMessages()
internal.bulkOverwriteGlobalApplicationCommands()
internal.bulkOverwriteGuildApplicationCommands()
internal.createAutoModerationRule()
internal.createChannelInvite()
internal.createDM()
internal.createFollowupMessage()
internal.createGlobalApplicationCommand()
internal.createGroupDM()
internal.createGuild()
internal.createGuildApplicationCommand()
internal.createGuildBan()
internal.createGuildChannel()
internal.createGuildEmoji()
internal.createGuildRole()
internal.createGuildScheduledEvent()
internal.createGuildSticker()
internal.createGuildTemplate()
internal.createGuildfromGuildTemplate()
internal.createInteractionResponse()
internal.createMessage()
internal.createReaction()
internal.createStageInstance()
internal.createWebhook()
internal.crosspostMessage()
internal.deleteAllReactions()
internal.deleteAllReactionsForEmoji()
internal.deleteAutoModerationRule()
internal.deleteChannel()
internal.deleteChannelPermission()
internal.deleteFollowupMessage()
internal.deleteGlobalApplicationCommand()
internal.deleteGuild()
internal.deleteGuildApplicationCommand()
internal.deleteGuildIntegration()
internal.deleteGuildEmoji()
internal.deleteGuildRole()
internal.deleteGuildScheduledEvent()
internal.deleteGuildSticker()
internal.deleteGuildTemplate()
internal.deleteInvite()
internal.deleteMessage()
internal.deleteOriginalInteractionResponse()
internal.deleteOwnReaction()
internal.deleteStageInstance()
internal.deleteUserReaction()
internal.deleteWebhook()
internal.deleteWebhookMessage()
internal.deleteWebhookwithToken()
internal.editApplicationCommandPermissions()
internal.editChannelPermissions()
internal.editFollowupMessage()
internal.editGlobalApplicationCommand()
internal.editGuildApplicationCommand()
internal.editMessage()
internal.editOriginalInteractionResponse()
internal.editWebhookMessage()
internal.executeGitHubCompatibleWebhook()
internal.executeSlackCompatibleWebhook()
internal.executeWebhook()
internal.followNewsChannel()
internal.getApplicationCommandPermissions()
internal.getApplicationRoleConnectionMetadataRecords()
internal.getAutoModerationRule()
internal.getChannel()
internal.getChannelInvites()
internal.getChannelMessage()
internal.getChannelMessages()
internal.getChannelWebhooks()
internal.getCurrentAuthorizationInformation()
internal.getCurrentBotApplicationInformation()
internal.getCurrentUser()
internal.getCurrentUserGuildMember()
internal.getCurrentUserGuilds()
internal.getFollowupMessage()
internal.getGateway()
internal.getGatewayBot()
internal.getGlobalApplicationCommand()
internal.getGlobalApplicationCommands()
internal.getGuild()
internal.getGuildApplicationCommand()
internal.getGuildApplicationCommandPermissions()
internal.getGuildApplicationCommands()
internal.getGuildAuditLog()
internal.getGuildBan()
internal.getGuildBans()
internal.getGuildChannels()
internal.getGuildEmoji()
internal.getGuildIntegrations()
internal.getGuildInvites()
internal.getGuildMember()
internal.getGuildPreview()
internal.getGuildPruneCount()
internal.getGuildRoles()
internal.getGuildScheduledEvent()
internal.getGuildScheduledEventUsers()
internal.getGuildSticker()
internal.getGuildTemplate()
internal.getGuildTemplates()
internal.getGuildVanityURL()
internal.getGuildVoiceRegions()
internal.getGuildWebhooks()
internal.getGuildWelcomeScreen()
internal.getGuildWidget()
internal.getGuildWidgetImage()
internal.getGuildWidgetSettings()
internal.getInvite()
internal.getOriginalInteractionResponse()
internal.getPinnedMessages()
internal.getReactions()
internal.getStageInstance()
internal.getSticker()
internal.getThreadMember()
internal.getUser()
internal.getUserConnections()
internal.getWebhook()
internal.getWebhookMessage()
internal.getWebhookWithToken()
internal.groupDMAddRecipient()
internal.groupDMRemoveRecipient()
internal.joinThread()
internal.leaveGuild()
internal.leaveThread()
internal.listActiveGuildThreads()
internal.listActiveThreads()
internal.listAutoModerationRules()
internal.listGuildEmojis()
internal.listGuildMembers()
internal.listGuildStickers()
internal.listJoinedPrivateArchivedThreads()
internal.listNitroStickerPacks()
internal.listPrivateArchivedThreads()
internal.listPublicArchivedThreads()
internal.listScheduledEventsforGuild()
internal.listThreadMembers()
internal.listVoiceRegions()
internal.modifyAutoModerationRule()
internal.modifyChannel()
internal.modifyCurrentMember()
internal.modifyCurrentUser()
internal.modifyCurrentUserVoiceState()
internal.modifyGuild()
internal.modifyGuildChannelPositions()
internal.modifyGuildEmoji()
internal.modifyGuildMember()
internal.modifyGuildRole()
internal.modifyGuildRolePositions()
internal.modifyGuildScheduledEvent()
internal.modifyGuildSticker()
internal.modifyGuildTemplate()
internal.modifyGuildWelcomeScreen()
internal.modifyGuildWidget()
internal.modifyStageInstance()
internal.modifyUserVoiceState()
internal.modifyWebhook()
internal.modifyWebhookWithToken()
internal.pinMessage()
internal.removeGuildBan()
internal.removeGuildMember()
internal.removeGuildMemberRole()
internal.removeThreadMember()
internal.searchGuildMembers()
internal.startThreadFromMessage()
internal.startThreadInForumChannel()
internal.startThreadWithoutMessage()
internal.syncGuildTemplate()
internal.triggerTypingIndicator()
internal.unpinMessage()
internal.updateApplicationRoleConnectionMetadataRecords()
内部事件
discord/application-command-permissions-update
discord/auto-moderation-action-execution
discord/auto-moderation-rule-create
discord/auto-moderation-rule-delete
discord/auto-moderation-rule-update
discord/channel-create
discord/channel-delete
discord/channel-pins-update
discord/channel-update
discord/guild-audit-log-entry-create
discord/guild-ban-add
discord/guild-ban-remove
discord/guild-create
discord/guild-delete
discord/guild-emojis-update
discord/guild-integrations-update
discord/guild-member-add
discord/guild-member-remove
discord/guild-member-update
discord/guild-members-chunk
discord/guild-role-create
discord/guild-role-delete
discord/guild-role-update
discord/guild-scheduled-event-create
discord/guild-scheduled-event-delete
discord/guild-scheduled-event-update
discord/guild-scheduled-event-user-add
discord/guild-scheduled-event-user-remove
discord/guild-stickers-update
discord/guild-update
discord/hello
discord/integration-create
discord/integration-delete
discord/integration-update
discord/interaction-create
discord/invalid-session
discord/invite-create
discord/invite-delete
discord/message-create
discord/message-delete-bulk
discord/message-delete
discord/message-reaction-add
discord/message-reaction-remove-all
discord/message-reaction-remove-emoji
discord/message-reaction-remove
discord/message-update
discord/presence-update
discord/ready
discord/reconnect
discord/resumed
discord/stage-instance-create
discord/stage-instance-delete
discord/stage-instance-update
discord/thread-create
discord/thread-delete
discord/thread-list-sync
discord/thread-member-update
discord/thread-members-update
discord/thread-update
discord/typing-start
discord/user-update
discord/voice-server-update
discord/voice-state-update
discord/webhooks-update