Displays the price of an Ethereum ERC-20 token in USD in the username of a Discord bot, and provides a /price
command for members to query the current price.
You can test out the bot for yourself here: discord.gg/rJQTV6gqcU
- Clone the repository
git clone https://github.com/reecehunter/erc-20-discord-price-bot
-
Create your bot application in the Discord Developer Portal.
-
Add the bot to your discord server using the URL generator in the Discord Developer Portal. It only needs the
bot
scope and theSend Messages
permission. -
Copy the .env.example file.
cp .env.example .env
- Fill in all the variables in your new
.env
. All data needed can be found in the Discord Developer Portal, Moralis account settings, and your own brain.
# The secret token for your Discord bot
DISCORD_BOT_TOKEN=
# The client ID of your Discord bot
DISCORD_CLIENT_ID=
# The ID of the server you put the bot in
DISCORD_GUILD_ID=
# The color you want the price command embed to have
EMBED_COLOR=15158332
# Moralis API key
# (Free API, just sign up for Moralis)
MORALIS_API_KEY=
# Name of the token to be displayed on the bot
TOKEN_NAME=$APE
# The smart contract address of the token
TOKEN_ADDRESS=0x4d224452801aced8b2f0aebe155379bb5d594381
# The chain the token is on
TOKEN_CHAIN=0x1
# How often the bot checks the price of the token in milliseconds
# (Discord has a rate limit)
UPDATE_FREQUENCY=3600000
- Install dependencies
npm install
- Deploy the price command
npm run deploy-commands
- Build the project
npm run build
- Start it up
npm run start
Your bot is now running!
Feel free to make a pull-request to add a feature or improve the current code.