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

使用interactions库的Discord机器人无法发送Embed消息怎么解决?

问题解决:interactions库发送Embed时的TypeError错误

问题场景

使用interactions库开发Discord机器人,尝试发送嵌入式消息时触发错误,报错提示_Context.send() got an unexpected keyword argument 'embed'。

原代码

import interactions
import discord

bot = interactions.Client(token="<REDACTED>")

@bot.command(
    name="test",
    description="Tests"
)
async def test(ctx: interactions.CommandContext):
    embed = interactions.Embed(
        title="testing",
        description="test purposes"
    )
    await ctx.send(embed = embed)

错误信息

payload = await super().send(content, **kwargs)

TypeError: _Context.send() got an unexpected keyword argument 'embed'

解决方法

interactions库的send方法不支持单独的embed参数,需将Embed对象放入列表,通过embeds(复数)参数传递:

修改后的代码

import interactions

# 无需导入discord库,interactions自身实现了Embed功能
bot = interactions.Client(token="<REDACTED>")

@bot.command(
    name="test",
    description="Tests"
)
async def test(ctx: interactions.CommandContext):
    embed = interactions.Embed(
        title="testing",
        description="test purposes"
    )
    # 将Embed放入列表,通过embeds参数发送
    await ctx.send(embeds=[embed])

补充说明

  • 移除了不必要的discord库导入,interactions库自带完整的Embed实现,无需依赖discord.py。
  • interactions的消息发送接口强制要求用embeds参数接收Embed列表,即使仅发送单个Embed也必须放在列表中。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 20:15:44