英文:
AttributeError: 'coroutine' object has no attribute 'edit' with discord.py
问题
"So I was working on a discord bot, that should edit its own message on a command, and I tried many things, but I kept getting the 'AttributeError: 'coroutine' object has no attribute 'edit'' Error, my code is this:
embed = discord.Embed(title="title")
embed.set_author(name="name", icon_url="image")
embed.add_field(name="name", value="some text", inline=True)
channel = Client.get_channel(channel-id)
msg = channel.fetch_message(message-id)
await msg.edit(embed=embed)
# Also: I've 'censored' the ID's
Apperently my error is at await msg.edit(embed=embed)
Please help, I have no idea, I've searched throught the whole internet and I found nothing really helpful. Thanks
I've tried awaiting the msg.edit()
function, as you see, but it still isn't working."
英文:
So I was working on a discord bot, that should edit its own message on a command, and I tried many things, but I kept getting the AttributeError: 'coroutine' object has no attribute 'edit'
Error, my code is this:
embed = discord.Embed(title="title")
embed.set_author(name="name", icon_url="image")
embed.add_field(name="name", value="some text", inline=True)
channel = Client.get_channel(channel-id)
msg = channel.fetch_message(message-id)
await msg.edit(embed=embed)
# Also: I've "censored" the ID's
Apperently my error is at await msg.edit(embed=embed)
Please help, I have no idea, I've searched throught the whole internet and I found nothing really helpful. Thanks
I've tried awaiting the msg.edit()
function, as you see, but it still isn't working.
答案1
得分: 0
channel.fetch_message
是协程。如果你没有在 它 上使用 await
,你将得到协程对象,而不是协程的最终结果。
msg = await channel.fetch_message(message_id)
msg.edit(embed=embed)
英文:
channel.fetch_message
is the coroutine. If you don't use await
on it, you get the coroutine
object, not the ultimate result of the coroutine.
msg = await channel.fetch_message(message_id)
msg.edit(embed=embed)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论