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

如何修复discord.py中Embed初始化代码的语法错误?

Discord.py Embed初始化语法错误修复

你的代码存在两个明确问题导致语法报错:

  1. 参数分隔符缺失:Python中函数的多个关键字参数必须用逗号分隔,哪怕每个参数单独占一行也不能省略。你写的title="title"、description="desc"、color=discord.Color.blue()之间没有添加逗号,这是直接触发语法错误的核心原因。

  2. 缩进层级错误:await ctx.send(embed=embed)的缩进不对,它属于games函数的内部代码,需要和embed = discord.Embed(...)保持相同的缩进级别。

修正后的代码如下:

@client.command(name="games")
async def games(ctx):
    embed = discord.Embed(
        title="title",
        description="desc",
        color=discord.Color.blue()
    )
    
    await ctx.send(embed=embed)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.17 01:20:34