Skip to content

Airmanf7/starter-discord-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

starter-discord-bot

Follow these instructions after deploying this repo on Cyclic.sh

Deploy to Cyclic

Set-up and configuration

1. Create discord application

Navigate to Discord's developer portal and create a new application

2. Get application keys and parameters

After creating the application, you are taken to the application's dashboard. There you can configure an app icon, description, etc.

Retrieve:

  • APPLICATION ID
  • PUBLIC KEY

3. Enable the Bot in the application

On the left hand side, go to Bot then click on Add Bot

You will need to create the bot token. Press Reset Token and confirm.

Retrieve the TOKEN string.

4. Adding the bot to your server

The easiest way to add the bot to your server is via url.

Go to OAuth2 > URL Generator on the left, select the permissions:

  • applications.commands - allows you to register slash commands
  • bot - this will show additional permissions for the bot
    • Send Messages - to allow the bot to send messages

Copy and navigate to the generated URL at the bottom.

The page will ask you to select a server to install your bot on, it will go through a few prompts to verify that you are human.

After you authorize, the bot will appear in your server.

Keep in mind, the bot does not yet have any code running, so it will not do anything just yet

5. Get your server ID

To get the server id, you first have to enable developer mode for in your discord user settings > advanced:

With developer mode on, you will be able to right click the discord server name to copy it's id:

Developer mode allows you to right click all kinds of things in discord to get their id's (channels, users, messages, etc.)

6. Set up environment variables

At this point, make sure you've collected all the variables you will use in your environment

Set up interactions endpoint

This step is VERY IMPORTANT, it lets discord know the url at which the bot is running. Discord will send interaction event payloads to this endpoint.

When you first enter the endpoint into the ui, discord will make a cryptographically signed request to your endpoint and expect you to verify the signature. This will establish trust between discord and your hosted bot.

  1. Make sure your bot is deployed to Cyclic
  2. Before entering the endpoint make sure the environment variables have been properly configured and that process.env.PUBLIC_KEY is set.
  3. Enter the endpoint url into discord and Save Changes
  • The interactions endpoint is using the verifyKeyMiddleware function to verify the keys automatically -
app.post('/interactions', verifyKeyMiddleware(PUBLIC_KEY), async (req, res) => {
    ...

Register slash commands

  1. Make sure all of the environment variables have been correctly set up
  2. Make a GET request to
    • https://[your bot's url].cyclic.app/register_commands This route makes a put request to register a /yo command on your discord sever
      app.get('/register_commands', async (req,res) =>{
      

Refer to the discord docs to extend this further

After registering commands, you should see them available in your discord server

Try the bot!

/yo

/dm

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%