How to get token prices on Discord
Discord has become a central hub for crypto communities to gather, share information, and manage projects. By incorporating live token prices directly into these communities, members can access timely market data without leaving their community environment.
Mobula API enables the integration of real-time token prices into a Discord server, enhancing engagement and providing immediate value to its members. This guide will detail how to set up a Discord bot using Mobula API to display token prices.
What you’ll need
- Knowledge in Python and Node.js programming languages.
- Knowledge of the Discord API.
- A database like MySQL, PostgreSQL, or MongoDB to store user data and transaction histories.
- A web cloud server to host the bot, ensuring its availability and responsiveness.
- An API key from the Dashboard (required for production; optional in development mode).
Walkthrough
Set up your bot on Discord
- Go to the Discord Developer Portal
- Click New Application, name your bot, and create it
- In the Bot tab, click Add Bot and confirm by clicking Yes, do it!
- Save the token provided for later use
Invite Your Bot to Your Server
- In the OAuth2 tab, under Scopes, check bot
- Under Bot Permissions, select permissions like Send Messages and Read Message History
- Open the generated URL in your browser to invite the bot to your server
Create the Bot Script
- Create a file named bot.js.
- Use the following script, replacing your_bot_token_here with your Discord bot token and your_api_key_here with your Mobula API key:
Run Your Bot
- Create a
.env
file in the same directory with your bot token and API key:
- Start your bot by running:
Deploy the Bot
Choose a hosting service such as Heroku for easy setup and a free tier suitable for small projects, AWS (Amazon Web Services) for robust services like EC2 or Elastic Beanstalk that are scalable, or DigitalOcean for affordable and scalable Droplets for larger deployments.
Deployment Process
- For Heroku:
- Install Heroku CLI: https://devcenter.heroku.com/articles/heroku-cli
- Login to your Heroku account in the terminal:
heroku login
- Create a new Heroku app:
heroku create
- Push your code to Heroku:
git push heroku master
- Scale your dyno:
heroku ps:scale web=0 worker=1
- Ensure you have a
Procfile
in your project root that looks like this:worker: node bot.js
Perform Functional Testing
- Local Testing: Before deploying, test the bot locally by running it and using commands in Discord to ensure it responds correctly.
- Staging Environment: If possible, use a staging environment on your hosting service to mimic production conditions.
Continuous Monitoring and Maintenance
- Logging: Implement logging in your bot’s code to track errors and unusual behaviors. Tools like Winston or Morgan can be useful.
- Error Handling: Make sure your bot has error handling for failed API calls or unexpected inputs.
- Performance Monitoring: Use tools provided by your hosting service or third-party services like Datadog or New Relic to monitor your application’s performance.
- Updates: Regularly update your bot’s dependencies and adjust to changes in the Discord API or Mobula API.
Need help?
Having issue integrating your API key? Reach out to us, response times < 1h.