Python 如何将API信息自动重新加载到Discord机器人?

Python 如何将API信息自动重新加载到Discord机器人?,python,reload,discord.py,Python,Reload,Discord.py,我现在正在玩Discord机器人,我想知道我是否可以每隔15秒自动重新加载一次 import asyncio @bot.event async def on_ready(): bot.loop.create_task(loopPlaying(bot)) async def playingLoop(bot) while True: r = requests.get('https://api.coinmarketcap.com/v1/ticker/bitcoin/

我现在正在玩Discord机器人,我想知道我是否可以每隔15秒自动重新加载一次

import asyncio

@bot.event
async def on_ready():
    bot.loop.create_task(loopPlaying(bot))

async def playingLoop(bot)
    while True:
        r = requests.get('https://api.coinmarketcap.com/v1/ticker/bitcoin/')
        for coin in r.json():
            await bot.change_presence(game=discord.Game(name='BTC Price: $' + (coin["price_usd"])))
            await asyncio.sleep(15)
上面的代码所做的是定义一个函数,每15秒更新一次价格。然后,当bot启动时,bot使用新函数创建后台任务