added slash command support

This commit is contained in:
Ashley Rosch
2021-08-20 03:19:57 -05:00
parent bc835922a5
commit e21d5573b1
6 changed files with 75 additions and 7 deletions

67
rolemanager/slash.ts Normal file
View File

@@ -0,0 +1,67 @@
import { SlashCommandBuilder } from "@discordjs/builders";
import { REST } from '@discordjs/rest';
import { Routes } from 'discord-api-types/v9';
import { GuildId, InteractionRoles } from './data';
const commands = [
//roles ======
new SlashCommandBuilder()
.setName('roles')
.setDescription('displays the role selections')
.addIntegerOption((option) => {
option
.setName('category')
.setDescription('the category of roles that will be displayed')
.setRequired(true)
InteractionRoles.forEach((opt, i) => option.addChoice(opt.message, i));
return option;
})
.toJSON(),
//rolesall ======
new SlashCommandBuilder()
.setName('rolesall')
.setDescription('displays the role selections for everyone')
.addIntegerOption((option) => {
option
.setName('category')
.setDescription('the category of roles that will be displayed')
InteractionRoles.forEach((opt, i) => option.addChoice(opt.message, i));
return option;
})
.addChannelOption(option =>
option
.setName('channel')
.setDescription('the channel the message(s) will be sent in'))
.toJSON(),
//updateroles ======
new SlashCommandBuilder()
.setName('updateroles')
.setDescription('updates the cached role options')
.toJSON()
];
const rest = new REST({ version: '9' }).setToken(require('fs').readFileSync('../token').toString());
export default async function refreshCommands(ClientId: string) {
try {
await rest.put(
Routes.applicationGuildCommands(ClientId, GuildId),
{ body: commands },
);
} catch (error) {
console.error(error);
}
}