chore: init
This commit is contained in:
commit
a07d554b41
10 changed files with 310 additions and 0 deletions
42
scripts/deployCommands.ts
Normal file
42
scripts/deployCommands.ts
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
import { REST, RESTPostAPIChatInputApplicationCommandsJSONBody, Routes } from "npm:discord.js";
|
||||
const { clientId, guildId, token } = Deno.env.toObject();
|
||||
import { Command } from "../types.ts";
|
||||
import { gatherCommandsPaths } from "../commands.ts";
|
||||
|
||||
const commands: RESTPostAPIChatInputApplicationCommandsJSONBody[] = [];
|
||||
async function register(commandPath: string) {
|
||||
const { default: command }: { default: Command } = await import(commandPath);
|
||||
if ("data" in command && "execute" in command) {
|
||||
commands.push(command.data.toJSON());
|
||||
console.log(`Deploying ${command.data.name}...`);
|
||||
} else {
|
||||
console.log(
|
||||
`[WARNING] The command at ${commandPath} is missing a required "data" or "execute" property.`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for (const commandPath of await gatherCommandsPaths()) {
|
||||
await register(commandPath)
|
||||
}
|
||||
|
||||
const rest = new REST().setToken(token);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
console.log(
|
||||
`Started refreshing ${commands.length} application (/) commands.`
|
||||
);
|
||||
|
||||
await rest.put(
|
||||
Routes.applicationGuildCommands(clientId, guildId),
|
||||
{ body: commands }
|
||||
);
|
||||
|
||||
console.log(
|
||||
`Successfully reloaded ${commands.length} application (/) commands.`
|
||||
);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue