Merge pull request #3 from discord/add-replit

Add replit support
This commit is contained in:
Shay DeWael
2022-05-05 15:26:18 -07:00
committed by GitHub
3 changed files with 9 additions and 4 deletions

View File

@@ -4,7 +4,7 @@ This project contains a basic rock-paper-scissors-style Discord app written in J
![Demo of app](/assets/getting-started-demo.gif?raw=true)
> ✨ A version of this code is also hosted **[on Glitch 🎏](https://glitch.com/edit/#!/getting-started-discord)**.
> ✨ A version of this code is also hosted **[on Glitch 🎏](https://glitch.com/~getting-started-discord)** and **[on Replit 🌀](https://replit.com/@shaydewael/discord-example-app)**
## Project structure
Below is a basic overview of the project structure:
@@ -50,6 +50,8 @@ Fetch the credentials from your app's settings and add them to a `.env` file (se
Fetching credentials is covered in detail in the [getting started guide](https://discord.com/developers/docs/getting-started).
> 🔑 Environment variables can be added to the `.env` file in Glitch or when developing locally, and in the Secrets tab in Replit (the lock icon on the left).
### Run the app
After your credentials are added, go ahead and run the app:

6
app.js
View File

@@ -17,6 +17,8 @@ import {
// Create an express app
const app = express();
// Get port, or default to 3000
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) }));
@@ -173,8 +175,8 @@ app.post('/interactions', async function (req, res) {
}
});
app.listen(3000, () => {
console.log('Listening on port 3000');
app.listen(PORT, () => {
console.log('Listening on port', PORT);
// Check if guild commands from commands.json are installed (if not, install them)
HasGuildCommands(process.env.APP_ID, process.env.GUILD_ID, [

View File

@@ -5,7 +5,8 @@
"main": "app.js",
"type": "module",
"scripts": {
"start": "node app.js"
"start": "node app.js",
"dev": "nodemon app.js"
},
"author": "Shay DeWael",
"license": "MIT",