commit a96549f6ad6f7ec8f08e011a619549d113470af7 Author: ethanf Date: Fri Nov 24 18:35:58 2023 -0600 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..36420af --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +config.json \ No newline at end of file diff --git a/bun.lockb b/bun.lockb new file mode 100755 index 0000000..76d1483 Binary files /dev/null and b/bun.lockb differ diff --git a/index.js b/index.js new file mode 100644 index 0000000..d273853 --- /dev/null +++ b/index.js @@ -0,0 +1,17 @@ +import { Client, GatewayIntentBits } from "discord.js"; +const { token } = require("./config.json"); +const client = new Client({ intents: [GatewayIntentBits.Guilds] }); + +client.on("ready", () => { + console.log(`Logged in as ${client.user.tag}!`); +}); + +client.on("interactionCreate", async (interaction) => { + if (!interaction.isChatInputCommand()) return; + + if (interaction.commandName === "hello") { + await interaction.reply("world"); + } +}); + +client.login(token); diff --git a/package.json b/package.json new file mode 100644 index 0000000..cd1063f --- /dev/null +++ b/package.json @@ -0,0 +1,6 @@ +{ "dependencies": { "discord.js": "^14.14.1" }, + "scripts": { + "start": "bun run index.js", + "register": "bun run register.js" + } +} \ No newline at end of file diff --git a/register.js b/register.js new file mode 100644 index 0000000..95f6464 --- /dev/null +++ b/register.js @@ -0,0 +1,23 @@ +import { REST, Routes } from "discord.js"; +const { token, client_id, guild_id } = require("./config.json"); + +const commands = [ + { + name: "hello", + description: "Replies 'world'", + }, +]; + +const rest = new REST({ version: "10" }).setToken(token); + +try { + console.log("Started refreshing application (/) commands."); + + await rest.put(Routes.applicationGuildCommands(client_id, guild_id), { + body: commands, + }); + + console.log("Successfully reloaded application (/) commands."); +} catch (error) { + console.error(error); +}