71 lines
1.9 KiB
JavaScript
71 lines
1.9 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.registerCommands = void 0;
|
|
const rest_1 = require("@discordjs/rest");
|
|
const v9_1 = require("discord-api-types/v9");
|
|
// list of commands to register with discord
|
|
const commands = [
|
|
{
|
|
name: 'open',
|
|
description: 'open a queue for this channel',
|
|
options: [
|
|
{
|
|
type: 4,
|
|
name: 'teamsize',
|
|
description: 'size of each team',
|
|
min_value: 1,
|
|
required: true
|
|
}
|
|
]
|
|
},
|
|
{
|
|
name: 'close',
|
|
description: 'close the queue for this channel'
|
|
},
|
|
{
|
|
name: 'queue',
|
|
description: 'view queue info'
|
|
},
|
|
{
|
|
name: 'join',
|
|
description: 'join the active queue'
|
|
},
|
|
{
|
|
name: 'leave',
|
|
description: 'leave the active queue'
|
|
},
|
|
{
|
|
name: 'player',
|
|
description: 'display player information',
|
|
options: [
|
|
{
|
|
type: 3,
|
|
name: 'username',
|
|
description: 'in game name or UniteApi short link',
|
|
required: true
|
|
}
|
|
]
|
|
}
|
|
], commandNames = commands.map(c => c.name);
|
|
/**
|
|
* register/reload commands on guild(s)
|
|
* @param token discord bot token
|
|
* @param clientId discord bot client id
|
|
* @param guildIds discord guild id(s)
|
|
*/
|
|
async function registerCommands(token, clientId, guildIds) {
|
|
const rest = new rest_1.REST({ version: '9' }).setToken(token);
|
|
if (typeof guildIds === 'string')
|
|
guildIds = [guildIds];
|
|
for (let i = 0; i < guildIds.length; i++) {
|
|
try {
|
|
await rest.put(v9_1.Routes.applicationGuildCommands(clientId, guildIds[i]), { body: commands });
|
|
console.log(`[${guildIds[i]}] registered command`);
|
|
}
|
|
catch (error) {
|
|
console.error(error);
|
|
}
|
|
}
|
|
}
|
|
exports.registerCommands = registerCommands;
|