Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Basic Discord app with examples

License

NotificationsYou must be signed in to change notification settings

discord/discord-example-app

Repository files navigation

This project contains a basic rock-paper-scissors-style Discord app written in JavaScript, built for thegetting started guide.

Demo of app

Project structure

Below is a basic overview of the project structure:

├── examples    -> short, feature-specific sample apps│   ├── app.js  -> finished app.js code│   ├── button.js│   ├── command.js│   ├── modal.js│   ├── selectMenu.js├── .env.sample -> sample .env file├── app.js      -> main entrypoint for app├── commands.js -> slash command payloads + helpers├── game.js     -> logic specific to RPS├── utils.js    -> utility functions and enums├── package.json├── README.md└── .gitignore

Running app locally

Before you start, you'll need to installNodeJS andcreate a Discord app with the proper permissions:

  • applications.commands
  • bot (with Send Messages enabled)

Configuring the app is covered in detail in thegetting started guide.

Setup project

First clone the project:

git clone https://github.com/discord/discord-example-app.git

Then navigate to its directory and install dependencies:

cd discord-example-appnpm install

Get app credentials

Fetch the credentials from your app's settings and add them to a.env file (see.env.sample for an example). You'll need your app ID (APP_ID), bot token (DISCORD_TOKEN), and public key (PUBLIC_KEY).

Fetching credentials is covered in detail in thegetting started guide.

🔑 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).

Install slash commands

The commands for the example app are set up incommands.js. All of the commands in theALL_COMMANDS array at the bottom ofcommands.js will be installed when you run theregister command configured inpackage.json:

npm run register

Run the app

After your credentials are added, go ahead and run the app:

node app.js

⚙️ A packagelikenodemon, which watches for local changes and restarts your app, may be helpful while locally developing.

If you aren't following thegetting started guide, you can move the contents ofexamples/app.js (the finishedapp.js file) to the top-levelapp.js.

Set up interactivity

The project needs a public endpoint where Discord can send requests. To develop and test locally, you can use something likengrok to tunnel HTTP traffic.

Install ngrok if you haven't already, then start listening on port3000:

ngrok http 3000

You should see your connection open:

Tunnel Status                 onlineVersion                       2.0/2.0Web Interface                 http://127.0.0.1:4040Forwarding                    https://1234-someurl.ngrok.io -> localhost:3000Connections                  ttl     opn     rt1     rt5     p50     p90                              0       0       0.00    0.00    0.00    0.00

Copy the forwarding address that starts withhttps, in this casehttps://1234-someurl.ngrok.io, then go to yourapp's settings.

On theGeneral Information tab, there will be anInteractions Endpoint URL. Paste your ngrok address there, and append/interactions to it (https://1234-someurl.ngrok.io/interactions in the example).

ClickSave Changes, and your app should be ready to run 🚀

Other resources

  • Readthe documentation for in-depth information about API features.
  • Browse theexamples/ folder in this project for smaller, feature-specific code examples
  • Join theDiscord Developers server to ask questions about the API, attend events hosted by the Discord API team, and interact with other devs.
  • Check outcommunity resources for language-specific tools maintained by community members.

About

Basic Discord app with examples

Topics

Resources

License

Stars

Watchers

Forks

Contributors14


[8]ページ先頭

©2009-2025 Movatter.jp