我想为不和谐制作一个机器人,它将使用智能机器人回复每条消息。我希望消息可以没有任何前缀或命令。我将使用cleverbot api 或selenium 来获得cleverbot 的答案。获取聊天中写的最后一条消息并回复它的最简单方法是什么?
像这样的东西:
网友:你最喜欢什么颜色?
机器人:绿色。
最佳答案
您应该使用 on_message event收听消息。然后你可以查看内容,得到你的回复,然后使用channel.send (通过 reference=message
)回复。
下面是一个示例,每次用户说“嗨”时,机器人都会回复“你好”:
@bot.event # or, if in a cog, @commands.Cog.listener()
async def on_message(message):
if message.author.bot:
return # ignore bots
if message.content == "hi":
await message.channel.send("hello", reference=message)
关于python - Discord.py 如何获取最后一条消息并在没有任何前缀/命令的情况下回复它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67186500/