为什么要删除这个错误?类型错误:on_message() 缺少 1 个必需的位置参数:“消息”

时间:2021-02-16 20:38:59

标签: discord.py

我正在尝试创建一个接受用户 ID 的代码,然后检查它是否与用户 ID 匹配,如果匹配则发送消息...我不断收到错误 TypeError: on_message() missing 1必需的位置参数:'message'...

username

1 个答案:

答案 0 :(得分:0)

您没有按照应有的方式定义函数。 on_message 事件只接受一个参数:message。在 ctx 事件中,您将不得不在没有 on_message 参数的情况下工作。考虑到这一点,您可以重新格式化您当前的函数代码:

@client.event
async def on_message(ctx,message):
    member = message.author.id 
    if member == <userid>:
        await ctx.send("yo whats up")
    else:
        return
    await client.process_commands(message)

到:

@client.event
# Only pass in "message" argument
async def on_message(message):
    member = message.author.id 
    if member == <userid>:
        # Use message.channel.send() instead of ctx.send()
        await message.channel.send("yo whats up")
    else:
        return
    await client.process_commands(message)