(discord.py) 检测消息中的某些关键字

Off*_*ond 2 discord.py

为了好玩,我打算制作一个语法机器人,我希望它在消息中找到某些关键字,而不是仅仅询问是否只有那个关键字。我没有找到任何接近我想要的东西。帮助?

Ben*_*jin 7

假设你要检查每发送邮件,您可以检查message.contenton_message使用Python的关键字事件。下面的示例代码,代码将检查消息中是否包含 FOO。

@bot.event
async def on_message(message):
    if 'FOO' in message.content:
        print('Keyword found in message')
        # Do stuff here
Run Code Online (Sandbox Code Playgroud)