Skip to content

Commit

Permalink
Get a command working; required demoting builders to 0.7.0 because of…
Browse files Browse the repository at this point in the history
  • Loading branch information
Auroratide committed Nov 8, 2021
1 parent 182485e commit 1b53b6a
Show file tree
Hide file tree
Showing 5 changed files with 199 additions and 8 deletions.
4 changes: 3 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const config = {
token: process.env.token,
token: process.env.DISCORD_TOKEN,
client: process.env.CLIENT_ID,
guild: process.env.GUILD_ID,
}
13 changes: 13 additions & 0 deletions deploy-commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { SlashCommandBuilder } from '@discordjs/builders'
import { REST } from '@discordjs/rest'
import { Routes } from 'discord-api-types/v9'
import { config } from './config.js'

const commands = [
new SlashCommandBuilder().setName('ping').setDescription('Reply with pong').toJSON(),
]

const rest = new REST({ version: '9' }).setToken(config.token)
rest.put(Routes.applicationGuildCommands(config.client, config.guild), { body: commands })
.then(() => console.log('Hooray! It worked.'))
.catch(console.error)
10 changes: 10 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,14 @@ client.once('ready', () => {
console.log('ready!')
})

client.on('interactionCreate', async (interaction) => {
if (!interaction.isCommand()) return;

const { commandName } = interaction

if (commandName === 'ping') {
await interaction.reply('pong!')
}
})

client.login(config.token)
176 changes: 169 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"main": "index.js",
"scripts": {
"start": "node -r dotenv/config .",
"deploy-commands": "node -r dotenv/config deploy-commands.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": {
Expand All @@ -14,6 +15,9 @@
},
"license": "ISC",
"dependencies": {
"@discordjs/builders": "0.7.0",
"@discordjs/rest": "^0.1.0-canary.0",
"discord-api-types": "^0.24.0",
"discord.js": "^13.3.1",
"dotenv": "^10.0.0"
}
Expand Down

0 comments on commit 1b53b6a

Please sign in to comment.