MCPcopy
hub / github.com/LAION-AI/Open-Assistant / commandHandler

Function commandHandler

discord-bots/oa-bot-js/src/handlers/commands.ts:11–55  ·  view source on GitHub ↗
(client)

Source from the content-addressed store, hash-verified

9// Create a new client instance
10const rest = new REST({ version: "10" }).setToken(process.env.TOKEN);
11export default async function commandHandler(client) {
12 const commands = [];
13 const commandsPath = path.join(__dirname, "../commands");
14
15 const commandFiles = fs
16 .readdirSync(commandsPath)
17 .filter((file) => file.endsWith(".js"));
18
19 for (const file of commandFiles) {
20 const filePath = `../commands/${file}`;
21 const { default: command } = await import(filePath);
22 // Set a new item in the Collection with the key as the command name and the value as the exported module
23 if (command.data && command.execute) {
24 client.commands.set(command.data.name, command);
25 commands.push(command.data.toJSON());
26 } else {
27 console.log(
28 chalk.yellow(
29 `[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`
30 )
31 );
32 }
33 }
34
35 // Construct and prepare an instance of the REST module
36 // and deploy your commands!
37
38 (async () => {
39 try {
40 console.log(
41 `Started refreshing ${commands.length} application (/) commands.`
42 );
43 // The put method is used to fully refresh all commands in the guild with the current set
44 const data = await rest.put(
45 Routes.applicationCommands(process.env.CLIENT_ID),
46 { body: commands }
47 );
48
49 console.log(`Successfully reloaded application (/) commands.`);
50 } catch (error) {
51 // And of course, make sure you catch and log any errors!
52 console.log(error);
53 }
54 })();
55}

Callers 1

bot.tsFile · 0.85

Calls 4

filterMethod · 0.80
setMethod · 0.80
logMethod · 0.80
putMethod · 0.45

Tested by

no test coverage detected