Now using SlashCommandBuilder

This commit is contained in:
2021-09-17 11:13:58 -07:00
parent 85a8f8e6cb
commit 31b2683142
+53 -31
View File
@@ -1,41 +1,63 @@
import Logger from "../libs/Logger"; import Logger from "../libs/Logger";
import DiscordProvider from "../providers/Discord"; import DiscordProvider from "../providers/Discord";
import { ApplicationCommand } from "discord.js" import { ApplicationCommand, Collection } from "discord.js"
import { SlashCommandBuilder } from "@discordjs/builders";
export const GLOBAL_COMMANDS = [ export const GLOBAL_COMMANDS: Object[] = [];
]; export const GUILD_COMMANDS: Object[] = [];
export const GUILD_COMMANDS = [ GUILD_COMMANDS.push(new SlashCommandBuilder().setName('help').setDescription('Show help menu').toJSON());
{ GUILD_COMMANDS.push(new SlashCommandBuilder().setName('ping').setDescription('Measure network latency').toJSON());
name: 'help', GUILD_COMMANDS.push(new SlashCommandBuilder().setName('invite').setDescription('Invite me to your server!').toJSON());
description: 'Show help menu' GUILD_COMMANDS.push(new SlashCommandBuilder()
}, .setName('say')
{ .setDescription('Make me say something')
name: 'ping', .addStringOption(option => option
description: 'Measure network latency' .setName('message')
}, .setDescription('Message you want me to say')
{ .setRequired(true)
name: 'invite', )
description: 'Invite me to your server!' );
},
{ GUILD_COMMANDS.push(new SlashCommandBuilder()
name: 'say', .setName('membershipscreening')
description: 'Make me say something', .setDescription('Membership screening')
options: [ .addSubcommand(enable => enable
{ .setName('enable')
name: 'message', .setDescription('Enable Membership screening')
type: 3, )
description: 'Message you want me to say', .addSubcommand(enable => enable
required: true .setName('disable')
} .setDescription('Disable Membership screening')
] )
} .addSubcommand(setrole => setrole
]; .setName('setrole')
.setDescription('Configure role of Membership screening')
.addRoleOption(option => option
.setName('role')
.setDescription('Role to give to user')
.setRequired(true)
)
)
.addSubcommand(setchannel => setchannel
.setName('setchannel')
.setDescription('Configure channel of Membership screening')
.addChannelOption(option => option
.setName('channel')
.setDescription('Channel to send request to')
.setRequired(true)
)
)
.addSubcommand(createmessage => createmessage
.setName('createmessage')
.setDescription('Create message for Membership screening')
)
);
export const registerAllGlobalCommands = async () => { export const registerAllGlobalCommands = async () => {
Logger.log('info', `Registering all global interaction commands`); Logger.log('info', `Registering all global interaction commands`);
await DiscordProvider.client.application?.commands.set(GLOBAL_COMMANDS); await DiscordProvider.client.application?.commands.set(JSON.parse(JSON.stringify(GLOBAL_COMMANDS)));
} }
export const unregisterAllGlobalCommands = async () => { export const unregisterAllGlobalCommands = async () => {
@@ -60,7 +82,7 @@ export const registerAllGuildsCommands = async () => {
if(!guildObject) continue; if(!guildObject) continue;
Logger.log('info', `Registering all interaction commands on guild ${guildObject.name} (${guildObject.id})`); Logger.log('info', `Registering all interaction commands on guild ${guildObject.name} (${guildObject.id})`);
await DiscordProvider.client.guilds.cache.get(guildObject.id)?.commands.set(GUILD_COMMANDS); await DiscordProvider.client.guilds.cache.get(guildObject.id)?.commands.set(JSON.parse(JSON.stringify(GUILD_COMMANDS)));
} }
} }