【问题标题】:TypeError: __init__() missing 1 required positional argument: 'field' (discord.py, embed)类型错误:__init__() 缺少 1 个必需的位置参数:“字段”(discord.py,嵌入)
【发布时间】:2021-03-09 14:16:17
【问题描述】:

当我启动我的 Discord Bot 时,它给了我错误:

    Ignoring exception in on_command_error
Traceback (most recent call last):
  File "C:\Users\jaron\Documents\PBot_rewrite\bot-env\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "C:\Users\jaron\Documents\PyBot_rewrite\bot.py", line 81, in stats
    embed = discord.Embed(title=f'{bot.user.name} Stats', description='\uFEFF', color=ctx.author.colour, timestamp=ctx.message.created_at)
TypeError: __init__() missing 1 required positional argument: 'field'

如果我运行此代码 sn-p:

    @bot.command()
async def stats(ctx):
    """
    A useful command that displays bot statistics.
    """
    pythonVersion = platform.python_version()
    dpyVersion = discord.__version__
    serverCount = len(bot.guilds)
    memberCount = len(set(bot.get_all_members()))

    embed = discord.Embed(title=f'{bot.user.name} Stats', description='\uFEFF', color=ctx.author.colour,
                          timestamp=ctx.message.created_at)

    embed.add_field(name='Bot Version:', value=bot.version)
    embed.add_field(name='<:python:818814561456095233> Python Version:', value=pythonVersion)
    embed.add_field(name='<:discordpy:818474661410766899> discord.py Version:', value=dpyVersion)
    embed.add_field(name='Total Guilds:', value=serverCount)
    embed.add_field(name='Total Members:', value=memberCount)
    embed.add_field(name='Bot Developer:', value='<@751092600890458203>')

    embed.set_author(name=bot.user.name, icon_url=bot.user.avatar_url)

    await ctx.send(embed=embed)

如果您需要更多信息,请询问:)

保持安全, 普基马

【问题讨论】:

  • 您是否尝试过输入手册values 来检查您的定义是否有问题?
  • Dominik 是什么意思?如何? (我是 discord.py 的新手 :()
  • 例如将value=pythonVersion 替换为"Test" 以检查您的代码是否有问题。我也会考虑将夹子分解成embed.title = ...embed.description = ... 等。
  • 现在是embed.add_field(name='Bot Version:', value=bot.version) TypeError: add_field() missing 1 required positional argument: 'self'
  • 试试self.bot.version。如果你已经在这方面苦苦挣扎,你应该先看看docs 或一些教程。

标签: python discord.py ctx


【解决方案1】:

field 似乎不是 discord.py 源代码中任何地方的参数名称,更不用说类的 __init__ 方法的参数了。我认为您的问题是,无论您从哪里获得 discord.Embed 都不是真正的、未修改的 discord.py 库。

【讨论】:

    猜你喜欢
    • 2022-01-11
    • 2021-07-06
    • 2023-03-19
    • 2020-01-29
    • 2017-10-30
    • 2021-09-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多