使用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
相关产品推荐
相关产品推荐

