added slash command support
This commit is contained in:
2
package-lock.json
generated
2
package-lock.json
generated
@@ -6,8 +6,8 @@
|
|||||||
"": {
|
"": {
|
||||||
"name": "ikea-canada-support",
|
"name": "ikea-canada-support",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@discordjs/builders": "^0.5.0",
|
||||||
"@discordjs/rest": "^0.1.0-canary.0",
|
"@discordjs/rest": "^0.1.0-canary.0",
|
||||||
"discord-api-types": "^0.22.0",
|
|
||||||
"discord.js": "^13.1.0"
|
"discord.js": "^13.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -9,8 +9,8 @@
|
|||||||
"ts-node": "^10.1.0"
|
"ts-node": "^10.1.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@discordjs/builders": "^0.5.0",
|
||||||
"@discordjs/rest": "^0.1.0-canary.0",
|
"@discordjs/rest": "^0.1.0-canary.0",
|
||||||
"discord-api-types": "^0.22.0",
|
|
||||||
"discord.js": "^13.1.0"
|
"discord.js": "^13.1.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
//array of Opt.Row|Opt.Menu, each one is a message that will be sent/understood
|
||||||
// - types/Opt.d.ts
|
// - types/Opt.d.ts
|
||||||
const InteractionRoles: (Opt.Row|Opt.Menu)[] = [
|
export const InteractionRoles: (Opt.Row|Opt.Menu)[] = [
|
||||||
{
|
{
|
||||||
type: 'menu',
|
type: 'menu',
|
||||||
message: 'Pronouns',
|
message: 'Pronouns',
|
||||||
palceholder: '',
|
palceholder: '',
|
||||||
id: 'rolemenu',
|
id: 'pronounsmenu',
|
||||||
max: 'all',
|
max: 'all',
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
@@ -106,7 +106,7 @@ const InteractionRoles: (Opt.Row|Opt.Menu)[] = [
|
|||||||
type: 'menu',
|
type: 'menu',
|
||||||
message: 'Other Roles',
|
message: 'Other Roles',
|
||||||
palceholder: '',
|
palceholder: '',
|
||||||
id: 'otherrolesmenu',
|
id: 'rolesmenu',
|
||||||
max: 'all',
|
max: 'all',
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
@@ -123,4 +123,4 @@ const InteractionRoles: (Opt.Row|Opt.Menu)[] = [
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
export default InteractionRoles;
|
export const GuildId = '861404201645244416';
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
"main": "index.ts",
|
"main": "index.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "ts-node .",
|
"start": "ts-node .",
|
||||||
"debug": "ts-node .",
|
"ts-node": "ts-node",
|
||||||
"watchdog": "./run.sh",
|
"watchdog": "./run.sh",
|
||||||
"tmux": "tmux new-session -d -s $npm_package_name \"./run.sh\"",
|
"tmux": "tmux new-session -d -s $npm_package_name \"./run.sh\"",
|
||||||
"resume": "tmux a -t $npm_package_name",
|
"resume": "tmux a -t $npm_package_name",
|
||||||
|
|||||||
67
rolemanager/slash.ts
Normal file
67
rolemanager/slash.ts
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
1
types/Opt.d.ts
vendored
1
types/Opt.d.ts
vendored
@@ -31,5 +31,6 @@ export interface RowButton {
|
|||||||
export interface Row {
|
export interface Row {
|
||||||
type: 'row';
|
type: 'row';
|
||||||
message: string;
|
message: string;
|
||||||
|
id: string; //not needed for api, just needed for slash commands
|
||||||
buttons: [RowButton?, RowButton?, RowButton?, RowButton?, RowButton?];
|
buttons: [RowButton?, RowButton?, RowButton?, RowButton?, RowButton?];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user