python - 如何循环从covid库中检索数据?
问题描述
covid = Covid()
covid.get_data()
confirmed = covid.get_total_confirmed_cases()
active = covid.get_total_active_cases()
recovered = covid.get_total_recovered()
deaths = covid.get_total_deaths()
@bot.group(invoke_without_command=True)
async def covid(ctx):
em = discord.Embed(title = "Covid-19", description = "test", color = ctx.author.color)
em.add_field(name = "test2", value = active)#
em.add_field(name = "test3", value = confirmed)
em.add_field(name = "test4", value = deaths)
em.add_field(name = "test5", value = recovered)
await ctx.send(embed = em)
")
当bot启动时,它从库中接收当前数据,当它发送消息时,它发送它,它只接收一次,启动后它不再更新这些数据,我需要确保数据即使机器人正在运行,也会更新和发送
解决方案
为什么不在命令执行时重新加载数据?
covidObject = Covid()
@bot.group(invoke_without_command=True)
async def covid(ctx):
covidObject.get_data()
confirmed = covidObject.get_total_confirmed_cases()
active = covidObject.get_total_active_cases()
recovered = covidObject.get_total_recovered()
deaths = covidObject.get_total_deaths()
em = discord.Embed(title = "Covid-19", description = "test", color = ctx.author.color)
em.add_field(name = "test2", value = active)#
em.add_field(name = "test3", value = confirmed)
em.add_field(name = "test4", value = deaths)
em.add_field(name = "test5", value = recovered)
await ctx.send(embed = em)
推荐阅读
- relational-database - 为什么这种级联投影不会改变投影结果?
- excel - 使用任务计划程序时,excel中的SAS存储过程不刷新?
- android-studio - 使用 Android Studio 在旧版 Android 4.4.2 上运行调试
- dart - Flutter 中的远程配置设备语言更改
- python - 使用示例应用程序的 uwsgi 文件指令运行应用程序时出现语法错误
- python - 带有自动完成 wxPython 的 ComboBox
- sql - 同一查询中的多个左连接导致“无效操作”错误
- javascript - 防止引用分配
- apache - 如果 url 没有带有 .htaccess 的前缀,如何重写它
- java - 如何实现一个包含 100 个随机元素的数组并对它们进行排序?