74 lines
1.9 KiB
TypeScript
74 lines
1.9 KiB
TypeScript
import { REST } from '@discordjs/rest';
|
|
import { Routes } from 'discord-api-types/v9';
|
|
|
|
// list of commands to register with discord
|
|
const commands = [
|
|
{
|
|
name: 'queue',
|
|
description: 'create a queue',
|
|
options: [
|
|
{
|
|
type: 4, //INTEGER
|
|
name: 'teamsize',
|
|
description: 'size of each team',
|
|
required: true,
|
|
min_value: 1
|
|
}
|
|
]
|
|
},
|
|
{
|
|
name: 'join',
|
|
description: 'join the active queue'
|
|
},
|
|
{
|
|
name: 'leave',
|
|
description: 'leave the active queue'
|
|
},
|
|
{
|
|
name: 'ready',
|
|
description: 'ready the queue and display team info'
|
|
},
|
|
{
|
|
name: 'cancel',
|
|
description: 'cancels the current queue (must have the Manage Messages permission)'
|
|
},
|
|
{
|
|
name: 'player',
|
|
description: 'display player information',
|
|
options: [
|
|
{
|
|
type: 3, //STRING
|
|
name: 'username',
|
|
description: 'in game name or UniteApi short link',
|
|
required: true
|
|
}
|
|
]
|
|
}
|
|
];
|
|
|
|
/**
|
|
* register/reload commands on guild(s)
|
|
* @param token discord bot token
|
|
* @param clientId discord bot client id
|
|
* @param guildIds discord guild id(s)
|
|
*/
|
|
export async function registerCommands(token: string, clientId: string, guildIds: string|string[]) {
|
|
|
|
const rest = new REST({ version: '9' }).setToken(token);
|
|
|
|
if (typeof guildIds === 'string')
|
|
guildIds = [guildIds];
|
|
|
|
for (let i = 0; i < guildIds.length; i++) {
|
|
try {
|
|
await rest.put(
|
|
Routes.applicationGuildCommands(clientId, guildIds[i]),
|
|
{ body: commands },
|
|
);
|
|
console.log(`[${guildIds[i]}] registered command`);
|
|
} catch (error) {
|
|
console.error(error);
|
|
}
|
|
}
|
|
|
|
} |