mirror of
https://github.com/discord/discord-example-app.git
synced 2026-08-24 10:13:20 -05:00
Update app for user-installable apps (#52)
* update code for user-install * readme
This commit is contained in:
@@ -4,8 +4,6 @@ This project contains a basic rock-paper-scissors-style Discord app written in J
|
||||
|
||||

|
||||
|
||||
> ✨ A version of this code is also hosted **[on Glitch 🎏](https://glitch.com/~getting-started-discord)** and **[on Replit 🌀](https://replit.com/github/discord/discord-example-app)**
|
||||
|
||||
## Project structure
|
||||
Below is a basic overview of the project structure:
|
||||
|
||||
@@ -91,7 +89,6 @@ You should see your connection open:
|
||||
Tunnel Status online
|
||||
Version 2.0/2.0
|
||||
Web Interface http://127.0.0.1:4040
|
||||
Forwarding http://1234-someurl.ngrok.io -> localhost:3000
|
||||
Forwarding https://1234-someurl.ngrok.io -> localhost:3000
|
||||
|
||||
Connections ttl opn rt1 rt5 p50 p90
|
||||
|
||||
@@ -22,6 +22,8 @@ const TEST_COMMAND = {
|
||||
name: 'test',
|
||||
description: 'Basic command',
|
||||
type: 1,
|
||||
integration_types: [0, 1],
|
||||
contexts: [0, 1, 2],
|
||||
};
|
||||
|
||||
// Command containing options
|
||||
@@ -38,6 +40,8 @@ const CHALLENGE_COMMAND = {
|
||||
},
|
||||
],
|
||||
type: 1,
|
||||
integration_types: [0, 1],
|
||||
contexts: [0, 2],
|
||||
};
|
||||
|
||||
const ALL_COMMANDS = [TEST_COMMAND, CHALLENGE_COMMAND];
|
||||
|
||||
+8
-2
@@ -55,7 +55,10 @@ app.post('/interactions', verifyKeyMiddleware(process.env.PUBLIC_KEY), async fun
|
||||
|
||||
// "challenge" command
|
||||
if (name === 'challenge' && id) {
|
||||
const userId = req.body.member.user.id;
|
||||
// Interaction context
|
||||
const context = req.body.context;
|
||||
// User ID is in user field for (G)DMs, and member for servers
|
||||
const userId = context === 0 ? req.body.member.user.id : req.body.user.id;
|
||||
// User's object choice
|
||||
const objectName = req.body.data.options[0].value;
|
||||
|
||||
@@ -137,8 +140,11 @@ app.post('/interactions', verifyKeyMiddleware(process.env.PUBLIC_KEY), async fun
|
||||
const gameId = componentId.replace('select_choice_', '');
|
||||
|
||||
if (activeGames[gameId]) {
|
||||
// Interaction context
|
||||
const context = req.body.context;
|
||||
// Get user ID and object choice for responding user
|
||||
const userId = req.body.member.user.id;
|
||||
// User ID is in user field for (G)DMs, and member for servers
|
||||
const userId = context === 0 ? req.body.member.user.id : req.body.user.id;
|
||||
const objectName = data.values[0];
|
||||
// Calculate result from helper function
|
||||
const resultStr = getResult(activeGames[gameId], {
|
||||
|
||||
Reference in New Issue
Block a user