0
\$\begingroup\$

I updated my discord bot, the code is here:

My bot can get the following:

  1. The price
  2. The rank
  3. The 24 hr volume
  4. 1 hr percent change
  5. 24 hr percent change
  6. 7d percent change
  7. Symbol
  8. Total supply
  9. (For some) a blurb about the creator (or creators) for you to read

All of this, in 1 short command!

Enjoy! If you have any questions or feedback, let me know!

import random
import asyncio
import requests
from discord import Game
from discord.ext.commands import Bot
import aiohttp
import discord
BOT_PREFIX = ("?", "!")
TOKEN = ""

client = Bot(command_prefix=BOT_PREFIX)


async def on_ready(self):
    await client.say("I am online!")


@client.command()
async def btc():
    url = 'https://api.coinmarketcap.com/v1/ticker/bitcoin/'
    response = requests.get(url)
    value = response.json()[0]["price_usd"]
    rank = response.json()[0]["rank"]
    supply = response.json()[0]["total_supply"]
    change1 = response.json()[0]["percent_change_1h"]
    change24 = response.json()[0]["percent_change_24h"]
    change72 = response.json()[0]["percent_change_7d"]
    vol24 = response.json()[0]["24h_volume_usd"]
    sym = response.json()[0]["symbol"]
    await client.say("Bitcoins price is: $" + value)
    await client.say("Bitcoins rank is: " + rank)
    await client.say("Bitcoins total supply is: " + supply)
    await client.say("Bitcoins percent change in the past hour is: " +change1)
    await client.say("Bitcoins percent change in the past 24 hours is:" + change24)
    await client.say("Bitcoins percent change in the past 7 days is: " + change72)
    await client.say("Bitcoins 24 hour volume is: " + vol24)
    await client.say("Bitcoins symbol is: " + sym)
    await client.say("_________________________________________________")
    await client.say("""In 2008, an unknown developer (or developer group) invented bitcoin as a new way to send value over the internet.
all we know about this person or persons, is that there pseudonym, or perhaps real name is Satoshi Nakamoto.""")
########################################################################done
@client.command()
async def eth():
    url = 'https://api.coinmarketcap.com/v1/ticker/ethereum/'
    response = requests.get(url)
    value = response.json()[0]["price_usd"]
    rank = response.json()[0]["rank"]
    supply = response.json()[0]["total_supply"]
    change1 = response.json()[0]["percent_change_1h"]
    change24 = response.json()[0]["percent_change_24h"]
    change72 = response.json()[0]["percent_change_7d"]
    vol24 = response.json()[0]["24h_volume_usd"]
    sym = response.json()[0]["symbol"]
    await client.say("Ethereum price is: $" + value)
    await client.say("Ethereums rank is: " + rank)
    await client.say("Ethereums total supply is: " + supply)
    await client.say("Ethereums percent change in the past hour is: " +change1)
    await client.say("Ethereums percent change in the past 24 hours is:" + change24)
    await client.say("Ethereums percent change in the past 7 days is: " + change72)
    await client.say("Ethereums 24 hour volume is: " + vol24)
    await client.say("Ethereums symbol is: " + sym)
    await client.say("_________________________________________________")
    await client.say("""In 2008, an unknown developer (or developer group) invented bitcoin as a new way to send value over the internet.
Four years later, a 19-year-old dreamed up a new platform based off of this innovation in an effort to transform the internet entirely.
This 19 year old, Vitalik Buterin later invented Ethereum, raising more then 18 million dollars.""")
###################################done
@client.command()
async def ripple():
    url = 'https://api.coinmarketcap.com/v1/ticker/ripple/'
    response = requests.get(url)
    value = response.json()[0]["price_usd"]
    rank = response.json()[0]["rank"]
    supply = response.json()[0]["total_supply"]
    change1 = response.json()[0]["percent_change_1h"]
    change24 = response.json()[0]["percent_change_24h"]
    change72 = response.json()[0]["percent_change_7d"]
    vol24 = response.json()[0]["24h_volume_usd"]
    sym = response.json()[0]["symbol"]
    await client.say("Ripples price is: $" + value)
    await client.say("Ripples rank is: " + rank)
    await client.say("Ripples total supply is: " + supply)
    await client.say("Ripples percent change in the past hour is: " +change1)
    await client.say("Ripples percent change in the past 24 hours is:" + change24)
    await client.say("Ripples percent change in the past 7 days is:" + change72)
    await client.say("Ripples 24 hour volume is:" + vol24)
    await client.say("Ripples symbol is: " + sym)
    await client.say("""The founders of the cryptocurrency Ripple are:
Chris Larsen, Jed McCaleb. They founded Ripple Labs, Inc. in 2012.""")
###########done
@client.command()
async def litecoin():
    url = 'https://api.coinmarketcap.com/v1/ticker/litecoin/'
    response = requests.get(url)
    value = response.json()[0]["price_usd"]
    rank = response.json()[0]["rank"]
    supply = response.json()[0]["total_supply"]
    change1 = response.json()[0]["percent_change_1h"]
    change24 = response.json()[0]["percent_change_24h"]
    change72 = response.json()[0]["percent_change_7d"]
    vol24 = response.json()[0]["24h_volume_usd"]
    sym = response.json()[0]["symbol"]
    await client.say("Litecoins price is: $" + value)
    await client.say("Litecoins rank is: " + rank)
    await client.say("Litecoins total supply is: " + supply)
    await client.say("Litecoins percent change in the past hour is: " +change1)
    await client.say("Litecoins percent change in the past 24 hours is:" + change24)
    await client.say("Litecoins percent change in the past 7 days is:" + change72)
    await client.say("Litecoins 24 hour volume is:" + vol24)
    await client.say("Litecoins symbol is: " + sym)
    await client.say("_________________________________________________")
    await client.say("""The original author of Litecoin is: Charlie Lee.
Litecoins inital release was in October of 2011.
Like Bitcoin, litecoin is a peer to peer cryptocurrency and a open source software project realesed under the MIT/X11 license.""")

###########done
async def neo():
    url = 'https://api.coinmarketcap.com/v1/ticker/neo/'
    response = requests.get(url)
    value = response.json()[0]["price_usd"]
    await client.say("NEO price is: $" + value)
@client.command()
async def eos():
    url = 'https://api.coinmarketcap.com/v1/ticker/eos/'
    response = requests.get(url)
    value = response.json()[0]["price_usd"]
    await client.say("EOS price is: $" + value)
@client.command()
async def dash():
    url = 'https://api.coinmarketcap.com/v1/ticker/dash/'
    response = requests.get(url)
    value = response.json()[0]["price_usd"]
    await client.say("DASH price is: $" + value)
@client.command()
async def zcash():
    url = 'https://api.coinmarketcap.com/v1/ticker/zcash/'
    response = requests.get(url)
    value = response.json()[0]["price_usd"]
    await client.say("Zcash price is: $" + value)
@client.command()
async def metal():
    url = 'https://api.coinmarketcap.com/v1/ticker/metal/'
    response = requests.get(url)
    value = response.json()[0]["price_usd"]
    await client.say("METAL coin price is: $" + value)
@client.command()
async def trump():
    url = 'https://api.coinmarketcap.com/v1/ticker/trumpcoin/'
    response = requests.get(url)
    value = response.json()[0]["price_usd"]
    await client.say("Trump Coin price is: $" + value)
@client.command()
async def gas():
    url = 'https://api.coinmarketcap.com/v1/ticker/gas/'
    response = requests.get(url)
    value = response.json()[0]["price_usd"]
    await client.say("GAS coin price is: $" + value)
@client.command()
async def gts():
    url = 'https://api.coinmarketcap.com/v1/ticker/game/'
    response = requests.get(url)
    value = response.json()[0]["price_usd"]
    await client.say("GTS coin price is: $" + value)
@client.command()
async def salus():
    url = 'https://api.coinmarketcap.com/v1/ticker/salus/'
    response = requests.get(url)
    value = response.json()[0]["price_usd"]
    await client.say("Salus coin price is: $" + value)

##########################
















client.run(TOKEN)
\$\endgroup\$
  • \$\begingroup\$ If this is a follow-up you should add part-X (or something similar) to the title and link to the previous question. \$\endgroup\$ – yuri Apr 1 '18 at 17:56
  • \$\begingroup\$ Alright @yuri I will do so! \$\endgroup\$ – Colea Apr 1 '18 at 17:58
  • \$\begingroup\$ I have just done so. The numbering needed to be improved anyway to make it more readable. \$\endgroup\$ – Jamal Apr 1 '18 at 17:59
  • \$\begingroup\$ Alright. @Jamal \$\endgroup\$ – Colea Apr 1 '18 at 17:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.