Python 缺少1个必需的位置参数:';味精';
在消息中键入Travis时,机器人没有响应。我怎样才能解决这个问题?请帮忙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
@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
作为参数传递给doctx.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
这是一个未知的表情符号,因为它是一个自定义表情符号,您的服务器中没有它