缺少 1 个必需的位置参数:'msg'

时间:2021-02-08 08:26:03

标签: python discord.py

机器人在消息中输入 Travis 时没有响应。我怎么解决这个问题?请帮忙

Error in row$year : $ operator is invalid for atomic vectors 

2 个答案:

答案 0 :(得分:2)

事件 on_message 不以 ctx 作为参数。如果您想将 ctx 作为参数传递给 ctx.send(),为了简单起见,您也可以使用 message.channel.send()

查看 documentation 以供参考。

您的代码已更正:

@client.event
async def on_message(msg):
    for word in filtered_words:
        if word in msg.content:
            await msg.delete()

    if "Travis" in msg.content:
        await msg.add_reaction("<:webp:784320972400361483>")
    
    if "Travis" in msg.content:
        await msg.channel.send(f"Hey {msg.author.mention}, He might be busy in real life so please DM him if you have a important work")
    
    await client.process_commands(msg)

答案 1 :(得分:1)

on_message 不接受 ctx 作为参数;您只需使用 message 即可完成您想做的所有事情。您的代码也是重复的,因为您可以在一个 if 块下组合 add_reactionsend。试试这个:

@client.event
async def on_message(message):
    for word in filtered_words:
        if word in message.content:
            await message.delete()

    if "Travis" in message.content:
        await message.add_reaction("<:webp:784320972400361483>")
        await message.channel.send(f"Hey {message.author.mention}, He might be busy in real life so please DM him if you have a important work")

    await client.process_commands(message)