Public
Makes adiscordbotformystufsarg
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.

Discord Ticket Bot

A Discord bot that responds with one of three random pre-programmed messages when a user types /ticket.

How it works

  • main.ts — HTTP endpoint that receives Discord interactions (slash commands) and replies with a random message
  • register-command.ts — One-time script that registers the /ticket slash command with Discord

Setup

1. Create a Discord application

Go to https://discord.com/developers/applications and create a new application.

2. Get your credentials

On the General Information tab, copy the Public Key.

On the Bot tab, copy the Token.

3. Add environment variables

Add these two env vars to this val:

šŸ‘‰ Add discordBotToken here: https://www.val.town/x/spiderjeremy/Nevermindthisonewillwork/environment-variables?key=discordBotToken

šŸ‘‰ Add discordPublicKey here: https://www.val.town/x/spiderjeremy/Nevermindthisonewillwork/environment-variables?key=discordPublicKey

4. Set the Interactions Endpoint URL

On the General Information tab in the Discord Developer Portal, scroll to Interactions Endpoint URL and paste your val's HTTP URL:

https://spiderjeremy--d99e2e9c7cb611f1b7bb1607ee4eb77e.web.val.run

Click Save Changes — Discord will send a PING to verify the endpoint is alive.

5. Register the slash command

Run register-command.ts once (via the Val Town UI or API) to register the /ticket command.

6. Invite the bot to your server

On the OAuth2 tab, use the URL Generator:

  • Select bot scope
  • Give it Send Messages permission
  • Open the generated URL and add the bot to your server

7. Test it!

Type /ticket in any channel your bot can see. You'll get one of three random replies!

Customizing the replies

Edit the REPLIES array at the top of main.ts:

const REPLIES = [ "šŸŽ« Thanks for opening a ticket! A team member will be with you shortly.", "šŸŽŸļø Your ticket has been received! Hang tight while we look into it.", "šŸ“‹ Ticket opened! We'll get back to you as soon as possible.", ];