I have a function that gets the top 10 cryptocurrencies by market cap
import os
import json
from requests import Session
def get_top10():
CMC_API_KEY=os.environ.get('CMC')
parameters={
'start':1,
'limit':5000
}
headers={
'Accepts':'application/json',
'X-CMC_PRO_API_KEY':CMC_API_KEY
}
session=Session()
session.headers.update(headers)
url='https://pro-api.coinmarketcap.com/v1/cryptocurrency/map'
response=session.get(url,params=parameters)
json_file=json.loads(response.text)['data']
top10_rank_to_slug = {d['rank']: d['slug'] for d in json_file}
top_10 = sorted(top10_rank_to_slug.items())[:10]
for rank,name in top_10:
print(rank,name)
but in order to pass it to my discord bot the function has to return a value not print it how can I do that (I want the bot to loop through the list then return the items one by one I dont want the bot to just return the list )
@client.command()
@commands.check(check_channel)
async def top10(ctx):
await ctx.send(get_top10())
client.run(token)
how do you suggest I do that??