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

discord.py中embed.add_field语法错误求助

修复Discord.py嵌入消息的语法错误

错误原因分析

你的代码出现语法错误的核心问题是未正确闭合discord.Embed()构造函数,在构造函数参数中直接调用了embed.set_author()方法,这不符合Python语法规范。此外,部分参数行的格式需要调整以避免歧义。

修正后的完整代码

if message.content.startswith('/help'):
    await message.delete()
    # 正确初始化Embed对象,先闭合构造函数括号
    embed = discord.Embed(
        title="Help",
        url="https://discord.com/channels/1138190037234749522/1139129893884547113",
        description="This should probably help you and starting players with everything they need to know about this server and what it can do.\nThis is also made in 10/08/2023 14:34 so do not expect this to contain everything that is needed and this will probably be outdated.\n\nPlease read the Quick Rules first.",
        colour=0xd7f736
    )
    # 单独调用set_author方法,不嵌入在构造函数内
    embed.set_author(
        name="Invadtrix",
        url="https://discord.gg/G76wVADr8H",
        icon_url="https://cdn.discordapp.com/emojis/1139112081073918002.webp?size=128&quality=lossless"
    )
    embed.add_field(
        name="Quick Rules",
        value="1. No Toxicity\n2. Respect everyone\n3. Don't be racist\n4. No NSFW in any channel\n5. Please don't break any\nRule\n6. Listen to moderators\n7. If you find anyone\nbreaking the rules:\nPlease contact a moderator\nor higher about them",
        inline=True
    )
    embed.add_field(
        name="Help",
        value="This wont tell you everything\nBut the Guide channel will\n------------------------------------\nIn the scripts channel you can get the scripts\nfor the games you play (Not all)\nThe bot channel is for bot commands\nIts the only channel where you can use bot commands\nGeneral already explains it\nBut if you don't understand: Its basically a place where you can talk with other people",
        inline=True
    )
    embed.add_field(
        name="Commands",
        value="This will not contain everything.\n\n/Help   /Commands   /Scripts   /Guide   /Announcements 💀\nThat's all for now.\nFor more commands go to the commands channel or say \"/Commands\"\nthey both are the same and will always be.",
        inline=True
    )
    embed.set_thumbnail(url="https://cdn.discordapp.com/emojis/1139112081073918002.webp?size=128&quality=lossless")
    embed.set_footer(text="Thank you")

    await message.author.send(embed=embed)

关键修复点

  • 将embed.set_author()从discord.Embed()的构造函数参数中移出,作为单独的方法调用
  • 确保discord.Embed()构造函数正确闭合括号
  • 调整参数换行格式,使代码结构更清晰,避免语法歧义

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 22:25:06