I am making a discord bot:
There is an async function that corresponds to a slash command. I have another function called count():
async def count(n):
for i in range(n):
yield i
and in the slash command function:
msg = ctx.respond("")
for i in count(n):
await msg.edit(i)
I got the following error:
discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: TypeError: 'async_generator' object is not iterable
So I looked up some suggestions on Stack Overflow and changed my code to:
global msg
msg = ctx.respond("")
async def counnnt(n):
async for i in count(n):
await msg.edit(i)
asyncio.run(counnnt(n))
Finally I got this error:
discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: AttributeError: 'coroutine' object has no attribute 'edit'
(obviously I am not doing count() in my bot but something very similar) I appreciate any suggestions :-)
CodePudding user response:
Use;
msg.edit_original_response(content="A")
CodePudding user response:
Most probably, ctx.respond
is async
so needs to be awiat
ed:
msg = await ctx.respond("")