I am curious on how to loop this certain part of my code every 10 seconds.
And how would I make it so instead the Discord API private messages you the price on !price execution rather then normally messages it in the channel?
import requests
import discord
import asyncio
url = 'https://cryptohub.online/api/market/ticker/PLSR/'
response = requests.get(url)
data = response.json()['BTC_PLSR']
client = discord.Client()
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print("PULSAR 4 LIFE")
print('------')
price = print('Price:', data['last'])
pulsar = float(data['last'])
pulsarx = "{:.9f}".format(pulsar)
await client.change_presence(game=discord.Game(name="PLSR Price: " + pulsarx))
@client.event
async def on_message(message):
if message.content.startswith('!price'):
url = 'https://cryptohub.online/api/market/ticker/PLSR/'
response = requests.get(url)
data = response.json()['BTC_PLSR']
price = print('PLSR Price:', data['last'])
pulsar = float(data['last'])
pulsarx = "{:.9f}".format(pulsar)
await client.send_message(message.channel, 'Price of PULSAR: ' + pulsarx)