使用discord.py发送Embed消息时遭遇TypeError错误的解决方案咨询
解决Discord机器人发送Embed时的
TypeError: send() got an unexpected keyword argument 'embed'问题 看起来你用的是discord-py-interactions(也就是interactions.py)库开发机器人,这个库的send()方法和常见的discord.py在参数设计上有区别,这正是报错的核心原因。
在discord.py里我们习惯用embed参数传递单个Embed对象,但interactions.py要求使用embeds参数,并且必须传入一个包含Embed对象的列表——哪怕你只发送一个Embed,也得用列表形式包裹。
具体修改步骤
把你代码里的发送语句:
await ctx.send(embed = embed1)
替换为:
await ctx.send(embeds=[embed1])
修改后的完整代码示例
@bot.command( name="my_first_command", description="This is the first command I made!", scope=[GUILD_ID], ) async def my_first_command(ctx): embed1 = discord.Embed( title=mob['name'], colour=0xE5E242, url=mob['url'], description="Famille: " + mob['type'], ) embed1.set_image(url=mob['imgUrl']) embed1.add_field(name="Caractéristiques", value=stats, inline=False) # 改用embeds参数并传入列表格式的Embed对象 await ctx.send(embeds=[embed1])
额外提示
如果你是刚从discord.py转用interactions.py,要注意这个库的API设计和discord.py有不少差异,比如消息组件、Embed发送逻辑都有区别,建议多参考官方文档里的消息发送相关内容,避免踩类似的参数坑。
内容的提问来源于stack exchange,提问作者Nayon
相关产品推荐
相关产品推荐

