Hello Everyone! My name is Andrew Fung, in this video, I will be showing you how you create a Crypto Bot in your discord server to track Crypto Prices and send user notifications in the form of messages to your devices. The crypto bot will be running 24/7 all the time as hosted by UpTimeRobot and will be constantly pinged every 5 minutes to keep the bot alive.
#discordbot #pricealert #cryptocurrency #python #replit
#cryptobot
Installation and Setup!
Coingecko API endpoint: https://api.coingecko.com/api/v3/coin...
Discord Python Documentation: https://discordpy.readthedocs.io/en/s...
UpTimeRobot service: https://uptimerobot.com
Discord Developer Portal: / discord
Source code for this project:
https://github.com/Andrew-FungKinHo/Y...
Check out my Github!
https://github.com/Andrew-FungKinHo
How I make my YouTube videos:
⌨️ Keyboard - Nuphy Air75 Mechanical Keyboard - https://amzn.to/3Xu4PD3
🎙 Microphone - MAONO A04 Professional Podcaster USB Microphone - https://amzn.to/3k8ocD5
🖱 Mouse - Microsoft Bluetooth Ergonomic Mouse - https://amzn.to/3CHhdHJ
🔌 Accessories - Laptop Docking Station for MacBook Pro - https://amzn.to/3CHi5Mv
Timestamps
0:00 | Intro
01:27 | Task 1: Send crypto price directly
03:12 | Task 2: List all the available coins
04:21 | Task 3: Check whether a coin is being supported
06:25 | Task 4: Price alerts scheduling algorithm explanation (whiteboard)
16:48 | Task 5: Price alerts scheduling algorithm (code)
20:45 | Out tro
Full Code:
———————————————————————————————
import discord
import requests
from replit import db
getting crypto data
def getCryptoPrices(crypto):
URL ="https://api.coingecko.com/api/v3/coin..."
r = requests.get(url=URL)
data = r.json()
putting the cryptocurrencies and their prices in db
for i in range(len(data)):
db[data[i]['id']] = data[i]['current_price']
if crypto in db.keys():
return db[crypto]
else:
return None
check if a cryptocurrency is supported in this bot
def isCryptoSupported(crypto):
if crypto in db.keys():
return True
else:
return False
instantiate a discord client
client = discord.Client()
@client.event
async def on_ready():
print(f'You have logged in as {client}')
channel = discord.utils.get(client.get_all_channels(),name='general')
await client.get_channel(channel.id).send('bot is now online!')
called whether there is a message in the chat
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('ya'):
await message.channel.send('yeet')
send crypto price directly
if message.content.lower() in db.keys():
await message.channel.send(f'The current price of {message.content} is: {getCryptoPrices(message.content.lower())} USD')
list all the available coins
if message.content.startswith('$list'):
cryptoSupportedList = [key for key in db.keys()]
await message.channel.send(cryptoSupportedList)
check whether a coin is being supported
if message.content.startswith('$support '):
cryptoToBeChecked = message.content.split('$support ',1)[1].lower()
await message.channel.send(isCryptoSupported(cryptoToBeChecked))
setting multiple price alerts
BOT_TOKEN = 'YOUR_TOKEN_HERE'
client.run(BOT_TOKEN)
———————————————————————————————
Feel free to drop a like and comment if you enjoy and video and let me know if you want me to do other types of programming videos ;) !!!