【问题标题】:TypeError: on_message() missing 1 required positional argument: 'user'类型错误:on_message() 缺少 1 个必需的位置参数:“用户”
【发布时间】:2021-05-10 03:53:57
【问题描述】:

我正在尝试创建一个事件,如果消息内容等于给定条件,那么它会执行某些操作,但是它一直向我显示此错误

TypeError: on_message() 缺少 1 个必需的位置参数:'user'


    @commands.Cog.listener()
    async def on_message(self, message, user:discord.User ):
        if message.content.lower() == f"<@{user.id}> beat <@{user.id}>":
            await message.send("It works!")

【问题讨论】:

  • 不能给事件添加更多参数,删除最后一个user参数

标签: python-3.x discord discord.py


【解决方案1】:

正如我在 cmets 中所说,您不能为事件添加更多参数,这不是命令

async def on_message(self, message):

要获取user 变量,您可以使用Message.author 变量

user = message.author

【讨论】:

    猜你喜欢
    • 2021-01-16
    • 2021-05-03
    • 2019-09-22
    • 2022-01-11
    • 1970-01-01
    • 2018-09-12
    • 2021-08-05
    • 2021-07-06
    相关资源
    最近更新 更多