类型错误:__init__() 缺少 1 个必需的位置参数:“字段”discord.py,嵌入

问题描述

当我启动我的 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'

如果我运行这个代码片段:

    @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',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)

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

注意安全, 普吉玛

解决方法

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