Public
Like
discord-bot
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.
This guide will walk you through creating a Discord bot and setting it up to work with the Discord DM Analyzer.
- Go to the Discord Developer Portal
- Click the "New Application" button in the top-right corner
- Enter a name for your application (e.g., "DM Analyzer")
- Accept the terms and click "Create"
- In the left sidebar, click on "Bot"
- Click the "Add Bot" button on the right
- Confirm by clicking "Yes, do it!"
- Under the bot's username, you'll see a "Reset Token" button
- Click "Reset Token" and confirm
- Copy the token that appears - this is your
DISCORD_TOKEN
- Under "Privileged Gateway Intents", enable:
- MESSAGE CONTENT INTENT
- SERVER MEMBERS INTENT
- Scroll down and click "Save Changes"
- In the left sidebar, click on "General Information"
- Under "Application ID", click the "Copy" button
- This is your
DISCORD_CLIENT_ID
- Open Discord
- Go to User Settings (gear icon next to your name)
- Select "Advanced" in the left sidebar
- Enable "Developer Mode"
- Close User Settings
- Right-click on your username anywhere in Discord
- Select "Copy ID"
- This is your
DISCORD_USER_ID
- Right-click on your spouse's username in Discord
- Select "Copy ID"
- This is your
SPOUSE_USER_ID
- In your project directory, create a
.env
file if you haven't already - Add the following variables:
DISCORD_TOKEN=your_discord_token_here DISCORD_CLIENT_ID=your_client_id_here DISCORD_USER_ID=your_user_id_here SPOUSE_USER_ID=spouse_user_id_here
- Go to OpenAI's website
- Sign up or log in
- Navigate to the API keys section
- Create a new API key
- Copy the key
- Add it to your
.env
file:OPENAI_API_KEY=your_openai_api_key_here
- In your project directory, run:
node discord-commands.js
- You should see "Successfully registered application commands."
- In the Discord Developer Portal, click on "OAuth2" in the left sidebar
- Click on "URL Generator"
- Under "Scopes", select:
- bot
- applications.commands
- Under "Bot Permissions", select:
- Read Messages/View Channels
- Send Messages
- Read Message History
- Copy the generated URL at the bottom
- Paste the URL in your browser
- Select a server where you want to add the bot
- Click "Authorize"
- Complete the CAPTCHA if prompted
- Install the Val.town CLI:
npm install -g val-town-cli
- Authenticate with Val.town:
vt login
- Deploy the application:
node val-town-deploy.js
- Set up environment variables in Val.town:
- Go to the Val.town dashboard
- Find your deployed functions
- Add the same environment variables from your
.env
file
- Set up a scheduled task for periodic DM fetching:
- Create a new scheduled task in Val.town
- Use the
discordDMBotCron
function - Choose a schedule (e.g., every 6 hours)
-
Start the local server:
node index.js
-
In Discord, use one of the slash commands:
/search What did we say about the IKEA table?
/links sofa
/categories
/analyze Summarize our furniture discussions
-
You can also manually trigger a DM fetch:
node val-town-cron.js
- Make sure the bot is running (
node index.js
) - Check if commands were registered successfully
- Verify that the bot has proper permissions
- Ensure both you and your spouse have DMed each other at least once
- Verify that all tokens and IDs in the
.env
file are correct - Check Discord developer portal for any token or permission issues
- Make sure you're logged in to Val.town CLI
- Check for any errors in the deployment logs
- Verify that environment variables are set correctly in Val.town
- Customize the bot's responses by editing the API endpoints in
api-server.js
- Add more categories for link classification in
database.js
- Enhance the AI queries by modifying prompts in
query-service.js
- Create a web interface that connects to your API endpoints