You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

请求解决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 a Message object. We save this to sent_msg so we can reference the exact message we need to edit later.
  • Use the message's edit method: Instead of client.edit, we call sent_msg.edit(embed=done_embed)—this targets the specific message we sent and updates its embed content.
  • Fixed typo: You had passContent=True which should be pass_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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 10:57:33