请求解决Discord机器人5秒后编辑嵌入消息时报错'Bot' object has no attribute 'edit'的问题
Fix: 'Bot' object has no attribute 'edit' in Discord.py
Ah, I see where you went wrong here! The error is happening because you're trying to call client.edit() to modify your message—but the Discord.py Bot class doesn't have an edit method. To edit a message, you need to work with the Message object that gets returned when you send the original embed, not the bot client itself.
What's the Root Issue?
In your code, you send the embed but don't save the resulting message instance. Instead, you tried to use client.edit, which doesn't exist for the Bot class. The correct approach is to store the message you send, then call edit() on that specific message object.
Corrected Code
import asyncio import discord from discord.ext import commands @client.command(pass_context=True) # Note: This is pass_context, not passContent! @commands.has_role("║Участники") async def test(ctx): loading = client.get_emoji(822491536993550397) # Create initial loading embed embed = discord.Embed(description=f'**{loading} Message will be edited in 5 seconds...**', colour=discord.Colour.blue()) # Save the sent message object to a variable sent_msg = await ctx.send(embed=embed) # Wait 5 seconds await asyncio.sleep(5) # Create the updated embed done_embed = discord.Embed(title=':white_check_mark: Done!', colour=discord.Colour.green()) # Edit the original message using its edit method await sent_msg.edit(embed=done_embed)
Key Fixes Explained
- Store the sent message: When you call
await ctx.send(), it returns aMessageobject. We save this tosent_msgso we can reference the exact message we need to edit later. - Use the message's edit method: Instead of
client.edit, we callsent_msg.edit(embed=done_embed)—this targets the specific message we sent and updates its embed content. - Fixed typo: You had
passContent=Truewhich should bepass_context=True. If you're using Discord.py v2.x, you can actually omit this parameter entirely since context is passed by default now.
内容的提问来源于stack exchange,提问作者ShadowNotFake
相关产品推荐
相关产品推荐

