@@ -525,8 +525,15 @@ var BARE_OS_DISCORD_PRESENCE_STATUS = {
|
||||
dnd: 1,
|
||||
invisible: 1
|
||||
}
|
||||
/** View Channel + Send Messages + Embed Links + Attach Files + Read History + Use App Commands */
|
||||
var BARE_OS_DISCORD_GUILD_INSTALL_PERMISSIONS = '2147597312'
|
||||
/**
|
||||
* Guild-install bot permissions (string bitfield).
|
||||
* View Channel + Send Messages + Embed Links + Attach Files + Read History.
|
||||
* Do not include Use Application Commands (1<<31): that bit is granted by the
|
||||
* `applications.commands` scope, and the signed 32-bit overflow has crashed
|
||||
* Discord's Add App UI. User-install params must send permissions "0".
|
||||
*/
|
||||
var BARE_OS_DISCORD_GUILD_INSTALL_PERMISSIONS = '117760'
|
||||
var BARE_OS_DISCORD_USER_INSTALL_PERMISSIONS = '0'
|
||||
var BARE_OS_DISCORD_COLOR = 0x5865f2
|
||||
var BARE_OS_DISCORD_COLOR_OK = 0x57f287
|
||||
var BARE_OS_DISCORD_COLOR_WARN = 0xfee75c
|
||||
@@ -2113,6 +2120,11 @@ function discordStampUserInstallCommand(json, ctx) {
|
||||
BARE_OS_DISCORD_CONTEXT_BOT_DM,
|
||||
BARE_OS_DISCORD_CONTEXT_PRIVATE
|
||||
]
|
||||
// dm_permission is deprecated and mutually exclusive with contexts.
|
||||
// Sending both has crashed Discord's in-app install UI.
|
||||
if (Object.prototype.hasOwnProperty.call(json, 'dm_permission')) {
|
||||
delete json.dm_permission
|
||||
}
|
||||
return json
|
||||
}
|
||||
|
||||
@@ -2140,7 +2152,10 @@ function discordUserInstallAppConfig() {
|
||||
}
|
||||
cfg[String(BARE_OS_DISCORD_INTEGRATION_USER)] = {
|
||||
oauth2_install_params: {
|
||||
scopes: ['applications.commands']
|
||||
scopes: ['applications.commands'],
|
||||
// Required by Install Params. Omitting it crashes Discord's Add App UI
|
||||
// (client BigInt-parses permissions). User install has no bot role.
|
||||
permissions: BARE_OS_DISCORD_USER_INSTALL_PERMISSIONS
|
||||
}
|
||||
}
|
||||
return { integration_types_config: cfg }
|
||||
@@ -2159,6 +2174,28 @@ async function discordEnableUserInstallApp(rest, Routes) {
|
||||
* User-install commands must be global. Also PUT guild commands when
|
||||
* DISCORD_GUILD_ID is set so the home server updates immediately.
|
||||
*/
|
||||
function discordGuildSlashCommand(json) {
|
||||
if (!json || typeof json !== 'object') return json
|
||||
const copy = {}
|
||||
for (const k in json) {
|
||||
if (!Object.prototype.hasOwnProperty.call(json, k)) continue
|
||||
if (k === 'integration_types' || k === 'contexts' || k === 'dm_permission') {
|
||||
continue
|
||||
}
|
||||
copy[k] = json[k]
|
||||
}
|
||||
return copy
|
||||
}
|
||||
|
||||
function discordGuildSlashBody(body) {
|
||||
const list = Array.isArray(body) ? body : []
|
||||
const out = []
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
out.push(discordGuildSlashCommand(list[i]))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
async function discordPutSlashCommands(rest, Routes, appId, body, opts) {
|
||||
opts = opts || {}
|
||||
const guildId = String(opts.guildId || '').trim()
|
||||
@@ -2173,7 +2210,7 @@ async function discordPutSlashCommands(rest, Routes, appId, body, opts) {
|
||||
}
|
||||
if (guildId && typeof Routes.applicationGuildCommands === 'function') {
|
||||
await rest.put(Routes.applicationGuildCommands(appId, guildId), {
|
||||
body: body
|
||||
body: discordGuildSlashBody(body)
|
||||
})
|
||||
out.guild = true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user