【发布时间】:2022-12-15 21:21:48
【问题描述】:
我正在制作一个不和谐的机器人:
有一个异步函数对应于一个斜杠命令。我有另一个函数 count():
async def count(n):
for i in range(n):
yield i
在斜杠命令函数中:
msg = ctx.respond("")
for i in count(n):
await msg.edit(i)
我收到以下错误:
discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: TypeError: 'async_generator' object is not iterable
所以我在 Stack Overflow 上查找了一些建议并将我的代码更改为:
global msg
msg = ctx.respond("")
async def counnnt(n):
async for i in count(n):
await msg.edit(i)
asyncio.run(counnnt(n))
最后我得到了这个错误:
discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: AttributeError: 'coroutine' object has no attribute 'edit'
(显然我没有在我的机器人中做 count() 而是非常相似的事情) 我感谢任何建议:-)
【问题讨论】:
标签: python asynchronous pycord