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

使用for循环修改Discord Embed页脚文本触发TypeError求解决

问题解决方法

错误原因

你用for循环遍历embed_dict["footer"]是错误的——Discord Embed的footer在字典结构里是单个字典对象(不是列表),遍历字典默认会迭代它的键名(字符串类型),所以循环里的footer是字符串,自然没法用footer["text"]赋值,触发了类型错误。

修正代码

不需要循环,直接修改footer字典里的text字段即可,同时注意变量名对应:

# 检查footer存在再修改,避免KeyError
if "footer" in embed_dict:
    embed_dict["footer"]["text"] = "new text"

# 生成新的Embed对象
embed_new = discord.Embed.from_dict(embed_dict)
# 用新生成的embed_new去编辑消息,而不是原来的raidedit1embed
await messageraids.edit(embed=embed_new)

额外说明

如果你的embed_dict里原本没有footer字段,需要先创建它:

embed_dict["footer"] = {"text": "new text"}

内容的提问来源于stack exchange,提问作者Daniel Andersen

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.16 11:25:21