This site was created with notaku.so! 🔥

How to make a Discord bot hosted 24/7 for free in 6 steps

Image without caption

Introduction

By the end of this tutorial you will have a Discord bot hosted 24/7, for free, forever, on Val Town, that responds to a basic /ping Slash Command.
Val Town is a social website to write, and deploy JavaScript from the browser.
No prior coding experience required. The vast majority of this tutorial is creating the bot on Discord and pasting your keys into Val Town. The actual coding parts are just clicking Run two times to fork over two pieces of code to your Val Town account.

Video Tutorial

If you prefer videos, here’s this same tutorial in a 3-minute YouTube video.

Step 1: Create a Discord app

  1. Go to the Discord Developer Portal and select “New Application” in the top right
Image without caption
  1. Enter a name for your Bot, accept the terms and press Create.
Image without caption

Step 2: Add the bot to your server

To invite your new bot to your server, you need to generate a link to click on.
  1. Head to the Oauth2 > URL Generator page.
  1. Select the bot scope, then the Send Messages permission.
Image without caption
  1. Copy the URL at the bottom of the page and paste it into a new browser tab.
  1. Click through the steps until you’re prompted to choose your server and press Continue.
Image without caption
  1. Press Authorize.
Image without caption
🎉 Your bot is now a member of your server! Now let’s get it to respond to Slash Commands.

Step 3: Login to Val Town

Val Town is a social website to write, run, and host JavaScript. You can create APIs, scheduled functions, email yourself, and persist small pieces of data — all from the browser and instantly deployed. There is a generous free plan, and no credit card required.
  1. Login or create an account.

Step 4: Save bot secrets

  1. Go to the “General Information” page
Image without caption
  1. Copy your Application ID
  1. Go to val.town/settings/secrets
  1. Create a new secret called discordAppId and paste in the value
  1. Copy your Public Key, saving it as discordPublicKey
  1. Go to the Bot page
  1. Click Reset Token and accept the warning
Image without caption
  1. Copy and paste it in val.town/settings/secrets as discordBotToken.

Step 5: Register a new Slash Command

  1. The embedded code below should have your name in the top-left corner. If you see anonymous, refresh this page. If you still see anonymous, ensure you’re logged into Val Town.
  1. Press Run to add the /ping command to your bot.

Step 6: Listen for Slash Commands

  1. Press Run to listen for Slash Commands and reply.
  1. Next to your val’s name, click 🔒 > Unlisted.
  1. In the val above, in the bottom-left corner of the val, click Script and change it to HTTP.
  1. Click on the URL at the bottom of that val that looks like https://username-handleDiscordInteraction.web.val.run
  1. Visit the General Information page for your bot and paste your copied endpoint into INTERACTIONS ENDPOINT URL and click Save Changes.
Image without caption

💬 Try it out!

Refresh Discord and try out your bot using /ping
Image without caption

Further Directions

Now that you have a basic Discord Bot setup, you’ll want to customize it to do exactly what you want. You’ll probably want to:
  1. Register a new Slash Command
  1. Connect your bot to APIs like OpenAI’s GPT or DallE
Come join us in the Val Town Discord if you get stuck, have questions, or want to show off your cool new bot!