使用discord.py开发Slash命令机器人发送Embed报错排查
问题分析
你犯了两个关键的API混用错误:
- 你使用的是
discord-py-interactions库的interactions.Client,但调用ctx.send()时用了原生discord.py的embed参数——这个库的send方法不支持该参数,对应的正确参数是**embeds**(复数形式)。 - 虽然可以传入原生
discord.Embed对象,但更推荐使用interactions库自带的Embed类,避免跨库API不兼容问题。
修复后的代码
import interactions import discord intents = discord.Intents.default() intents.message_content = True bot = interactions.Client(token=TOKEN) @bot.command( name="debug", description="Test for errors in bot", scope=<id>, # 替换为你的服务器ID ) async def debug(ctx: interactions.CommandContext): # 方式1:使用interactions库的Embed类(推荐) help_embed = interactions.Embed(title="Modules:") await ctx.send(embeds=help_embed) # 方式2:兼容原生discord.Embed(需用embeds参数) # help_embed = discord.Embed(title="Modules:") # await ctx.send(embeds=help_embed) bot.start()
补充说明
interactions库的send方法中,embeds参数既可以传单个Embed实例,也可以传多个实例组成的列表。- 确保已正确安装依赖:
pip install discord-py-interactions
内容的提问来源于stack exchange,提问作者i cant think of a name
相关产品推荐
相关产品推荐

