Port a commands and utils modules from getting-started

This commit is contained in:
Eryn Wells 2022-11-12 10:29:21 -08:00
parent 50febb14bd
commit 494576d19c
3 changed files with 105 additions and 1 deletions

14
app.js
View file

@ -1,5 +1,10 @@
import 'dotenv/config';
import express from 'express';
import { verifyDiscordRequest } from './utils.js';
import {
TEST_COMMAND,
hasGuildCommands,
} from './commands.js';
// Create an express app
const app = express();
@ -8,8 +13,15 @@ const app = express();
const PORT = process.env.PORT || 3000;
// Parse request body and verifies incoming requests using discord-interactions package
app.use(express.json({ verify: VerifyDiscordRequest(process.env.PUBLIC_KEY) }));
app.use(express.json({
verify: verifyDiscordRequest(process.env.PUBLIC_KEY)
}));
app.listen(PORT, () => {
console.log('Listening on port', PORT);
// Check if guild commands from commands.js are installed (if not, install them)
hasGuildCommands(process.env.APP_ID, process.env.GUILD_ID, [
TEST_COMMAND,
]);
});