Discord.py 缺少 1 个必需的位置参数:'ctx'

时间:2021-04-07 12:15:24

标签: python discord discord.py

当我尝试运行该命令时,我总是收到此错误消息:TypeError: on_ready() missing 1 required positional argument: 'ctx'

@client.event
async def on_ready(ctx):
    with open('channel.json', 'r') as f:
        jchannel = json.load(f)

    channel = jchannel[str(ctx.guild.id)]

    await channel.send(f"Welcome!")

完全错误:

回溯(最近一次调用最后一次): 文件“C:\Users\NexaHn\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py”,第 343 行,在 _run_event 等待 coro(*args, **kwargs) 类型错误:on_ready() 缺少 1 个必需的位置参数:'ctx'

1 个答案:

答案 0 :(得分:3)

如果您阅读文档,您会发现 on_ready 不接受任何参数。无法传入 ctx。

另外,你想做什么?欢迎命令?有一个名为 on_member_join 的函数,如果您正在尝试执行我认为您正在尝试完成的操作,请查看该函数。