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

