AttributeError: 'coroutine' object has no attribute 'edit' with discord.py

huangapple go评论75阅读模式
英文:

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)

huangapple
  • 本文由 发表于 2023年2月23日 22:21:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/75546086.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定