Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 缺少1个必需的位置参数:';味精';_Python_Discord.py - Fatal编程技术网

Python 缺少1个必需的位置参数:';味精';

Python 缺少1个必需的位置参数:';味精';,python,discord.py,Python,Discord.py,在消息中键入Travis时,机器人没有响应。我怎样才能解决这个问题?请帮忙 @client.event async def on_message(msg, ctx): for word in filtered_words: if word in msg.content: await msg.delete() if "Travis" in msg.content: await msg.add_react

在消息中键入Travis时,机器人没有响应。我怎样才能解决这个问题?请帮忙

@client.event
async def on_message(msg, ctx):
    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 ctx.send(f"Hey {ctx.author.mention}, He might be busy in real life so please DM him if you have a important work")
    

   


    await client.process_commands(msg)
@client.event
异步def on_消息(消息,ctx):
对于已过滤单词中的单词:
如果msg.content中有单词:
等待消息。删除()
如果msg.content中有“Travis”:
等待消息。添加反应(“”)
如果msg.content中有“Travis”:
等待ctx.send(f“嘿{ctx.author.提提},他在现实生活中可能很忙,所以如果你有重要的工作,请给他发DM”)
等待客户端处理命令(msg)

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

@client.event
异步def on_消息(消息):
对于已过滤单词中的单词:
如果message.content中有单词:
等待消息。删除()
如果message.content中的“Travis”:
等待消息。添加反应(“”)
wait message.channel.send(f“嘿{message.author.antime},他在现实生活中可能很忙,所以如果你有重要的工作,请给他发DM”)
等待客户端处理命令(消息)

消息上的事件
未将
ctx
作为参数。如果您想将
ctx
作为参数传递给do
ctx.send()
,为了简单起见,还可以使用
message.channel.send()

请查看该文档以供参考

您的代码已更正:

@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)
@client.event
异步def on_消息(消息):
对于已过滤单词中的单词:
如果msg.content中有单词:
等待消息。删除()
如果msg.content中有“Travis”:
等待消息。添加反应(“”)
如果msg.content中有“Travis”:
等待msg.channel.send(f“嘿{msg.author.antime},他在现实生活中可能很忙,所以如果你有重要的工作,请给他发DM”)
等待客户端处理命令(msg)

您在事件中未通过
ctx
这是一个未知的表情符号,因为它是一个自定义表情符号,您的服务器中没有它