TypeError:__init __()接受1个位置参数,但给了2个discord.py

Lysander12 PT

所以我试图在我的机器人中创建一个设置命令,用户可以在其中选择他想要的东西。问题是我无法按自己的意愿运行它。

我有这个作为我的代码

# Function to write changes to file
def set_adminrole(guild: Guild, *, role: Role):
    with open("admins.json") as f:
        roles = json.load(f)

    roles[str(guild.id)] = role.id

    with open("admins.json", 'w') as f:
        json.dump(roles, f, indent=4)

# Actual command

-- Not important code --

await ctx.send(f"Now, mention the role you want it to be the admin role")
    role: Message = await bot.wait_for("message", check=check)
    actualrole: Role = Role(role)
    set_adminrole(ctx.message.guild, role=actualrole)
    await ctx.send(f"Admin role changed to {Role(role.content).mention}... Let's keep going")

当我提到将其设置为管理员角色的角色时,会引发此错误:

Ignoring exception in command setup:
Traceback (most recent call last):
  File "C:\Users\xlysa\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "D:/Ficheiros/Pastas/Tudo/Coding/Python/Projects/Server-Utils/bot.py", line 262, in start_setup
    actualrole: Role = Role(role)
TypeError: __init__() takes 1 positional argument but 2 were given

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\xlysa\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py", line 903, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\xlysa\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 855, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\xlysa\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: __init__() takes 1 positional argument but 2 were given

感谢帮助

bravosierra99

因此,您会收到一条消息,然后尝试使用该消息创建一个Role对象。这没有道理。查看Role对象的构造函数,并正确调用它。

await ctx.send(f"Now, mention the role you want it to be the admin role")
    role: Message = await bot.wait_for("message", check=check)
    actualrole: Role = Role(role) #<- what are you doing here????
    set_adminrole(ctx.message.guild, role=actualrole)
    await ctx.send(f"Admin role changed to 

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Discord.py重写齿轮:TypeError:__init __()缺少1个必需的位置参数:'func'

来自分类Dev

TypeError:init_animals()接受1个位置参数,但给出了2个

来自分类Dev

Money和TypeError:__init __()接受1到2个位置参数,但给出了3个

来自分类Dev

TypeError:init_animals()接受1个位置参数,但给出了2个

来自分类Dev

Money和TypeError:__init __()接受1到2个位置参数,但给出了3个

来自分类Dev

TypeError:__init __()接受1个位置参数,但给出了2个(使用Pytesseract的Python多处理)

来自分类Dev

Django客户端获取:TypeError:__init __()接受1个位置参数,但给出了2个

来自分类Dev

TypeError:__init __()接受1个位置参数,但给出了3个

来自分类Dev

多重继承,TypeError:__init __()接受2个位置参数,但给出了3个

来自分类Dev

__init __()接受1个位置参数,但给了2个登录页面

来自分类Dev

TypeError:quit()接受1个位置参数,但给出了2个(键盘绑定)

来自分类Dev

TypeError:as_view()接受1个位置参数,但给出了2个

来自分类Dev

TypeError:login()接受1个位置参数,但给出了2个

来自分类Dev

TypeError:函数接受1个位置参数,但给了2个kivy python

来自分类Dev

PyTorch-TypeError:forward()接受1个位置参数,但给出了2个

来自分类Dev

TypeError:function()接受1个位置参数,但给出了2个

来自分类Dev

/ users / login / __init __()处的TypeError带有1个位置参数,但给出了2个

来自分类Dev

TypeError at : / __init__() 需要 1 个位置参数,但给出了 2 个

来自分类Dev

django-rest-knox在生产中:“ TypeError:create()接受1个位置参数,但给出了2个”

来自分类Dev

错误:__ init __()接受1个位置参数,但给出了7个

来自分类Dev

__init __()接受1个位置参数,但给出了8个

来自分类Dev

__init __()接受1到3个位置参数,但给出了4个

来自分类Dev

Python:__init __()接受2个位置参数,但给出了3个

来自分类Dev

TypeError:destroy()接受0个位置参数,但给出了1个

来自分类Dev

TypeError:接受0个位置参数,但给出了1个

来自分类Dev

TypeError:open()接受0个位置参数,但给定2个

来自分类Dev

TypeError:structural_similarity()接受2个位置参数,但给出了8个

来自分类Dev

TypeError:androlyze_main()接受2个位置参数,但给出了4个

来自分类Dev

PYTHON:TypeError:DriverSpeed()接受0个位置参数,但给定1

Related 相关文章

  1. 1

    Discord.py重写齿轮:TypeError:__init __()缺少1个必需的位置参数:'func'

  2. 2

    TypeError:init_animals()接受1个位置参数,但给出了2个

  3. 3

    Money和TypeError:__init __()接受1到2个位置参数,但给出了3个

  4. 4

    TypeError:init_animals()接受1个位置参数,但给出了2个

  5. 5

    Money和TypeError:__init __()接受1到2个位置参数,但给出了3个

  6. 6

    TypeError:__init __()接受1个位置参数,但给出了2个(使用Pytesseract的Python多处理)

  7. 7

    Django客户端获取:TypeError:__init __()接受1个位置参数,但给出了2个

  8. 8

    TypeError:__init __()接受1个位置参数,但给出了3个

  9. 9

    多重继承,TypeError:__init __()接受2个位置参数,但给出了3个

  10. 10

    __init __()接受1个位置参数,但给了2个登录页面

  11. 11

    TypeError:quit()接受1个位置参数,但给出了2个(键盘绑定)

  12. 12

    TypeError:as_view()接受1个位置参数,但给出了2个

  13. 13

    TypeError:login()接受1个位置参数,但给出了2个

  14. 14

    TypeError:函数接受1个位置参数,但给了2个kivy python

  15. 15

    PyTorch-TypeError:forward()接受1个位置参数,但给出了2个

  16. 16

    TypeError:function()接受1个位置参数,但给出了2个

  17. 17

    / users / login / __init __()处的TypeError带有1个位置参数,但给出了2个

  18. 18

    TypeError at : / __init__() 需要 1 个位置参数,但给出了 2 个

  19. 19

    django-rest-knox在生产中:“ TypeError:create()接受1个位置参数,但给出了2个”

  20. 20

    错误:__ init __()接受1个位置参数,但给出了7个

  21. 21

    __init __()接受1个位置参数,但给出了8个

  22. 22

    __init __()接受1到3个位置参数,但给出了4个

  23. 23

    Python:__init __()接受2个位置参数,但给出了3个

  24. 24

    TypeError:destroy()接受0个位置参数,但给出了1个

  25. 25

    TypeError:接受0个位置参数,但给出了1个

  26. 26

    TypeError:open()接受0个位置参数,但给定2个

  27. 27

    TypeError:structural_similarity()接受2个位置参数,但给出了8个

  28. 28

    TypeError:androlyze_main()接受2个位置参数,但给出了4个

  29. 29

    PYTHON:TypeError:DriverSpeed()接受0个位置参数,但给定1

热门标签

归档