【发布时间】:2021-05-16 15:24:40
【问题描述】:
再次,我一直在思考我的准备问题。我刚开始为不和谐写机器人,坐了几个小时寻找错误,最后我还是找不到。这就是为什么我写一个论坛帖子作为最后的手段。我期待您的帮助,并提前感谢您。
这是我的代码:
@tasks.loop(hours=24)
async def covid_hour():
channel = client.get_channel(809881992367702117),
embed = discord.Embed(
title = "Dane dot. COVID-19 w Polsce:",
color = discord.Color.blue(),
),
url = 'API'
async with aiohttp.ClientSession() as session:
raw_response = await session.get(url)
response = await raw_response.text()
response = json.loads(response)
embed.set_author(name=str(f'{date}'))
embed.add_field(name='• **Kraj**:', value=str(f"Polska"), inline=False)
embed.add_field(name='• **Nowe zakażenia**:', value=str(f"{response['dailyInfected']}"), inline=True)
embed.add_field(name='• **Nowe zgony**:', value=str(f"{response['dailyDeceased']}"), inline=True)
embed.add_field(name='• **Nowe testy**:', value=str(f"{respons['dailyTested']}"), inline=True)
embed.add_field(name='• **Nowe uzdrowienia**:', value=str(f"{response['dailyRecovered']}"), inline=True)
embed.add_field(name='• **Aktualnie zakażonych**:', value=str(f"{respons['activeCase']}"), inline=True)
embed.add_field(name='• **Łącznie potwierdzonych**:', value=str(f"{response['infected']}"), inline=True)
embed.add_field(name='• **Łączne zgony**:', value=str(f"{response['deceased']}"), inline=True)
embed.add_field(name='• **Wyzdrowiałych**:', value=str(f"{response['recovered']}"), inline=True)
embed.add_field(name='• **Nowych na kwarantannie**:', value=str(f"{response['dailyQuarantine']}"), inline=True)
embed.set_footer(text="dBot created by Diablo#4700")
await channel.send(embed=embed)
#await channel.send('`` ``')
控制台错误:
Unhandled exception in internal background task 'covid_hour'.
Traceback (most recent call last):
File "C:\Users\konta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\ext\tasks\__init__.py", line 101, in _loop
await self.coro(*args, **kwargs)
File "bot.py", line 64, in covid_hour
embed.set_author(name=str2(f'{date}'))
AttributeError: 'tuple' object has no attribute 'set_author'
【问题讨论】:
标签: python-3.x discord discord.py