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

View File

@@ -2,12 +2,12 @@ import * as Opt from "../types/Opt";
//array of Opt.Row|Opt.Menu, each one is a message that will be sent/understood
// - types/Opt.d.ts
const InteractionRoles: (Opt.Row|Opt.Menu)[] = [
export const InteractionRoles: (Opt.Row|Opt.Menu)[] = [
{
type: 'menu',
message: 'Pronouns',
palceholder: '',
id: 'rolemenu',
id: 'pronounsmenu',
max: 'all',
options: [
{
@@ -106,7 +106,7 @@ const InteractionRoles: (Opt.Row|Opt.Menu)[] = [
type: 'menu',
message: 'Other Roles',
palceholder: '',
id: 'otherrolesmenu',
id: 'rolesmenu',
max: 'all',
options: [
{
@@ -123,4 +123,4 @@ const InteractionRoles: (Opt.Row|Opt.Menu)[] = [
}
];
export default InteractionRoles;
export const GuildId = '861404201645244416';

View File

@@ -3,7 +3,7 @@
"main": "index.ts",
"scripts": {
"start": "ts-node .",
"debug": "ts-node .",
"ts-node": "ts-node",
"watchdog": "./run.sh",
"tmux": "tmux new-session -d -s $npm_package_name \"./run.sh\"",
"resume": "tmux a -t $npm_package_name",

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);
}
}