Z
Z
Zakkaru2021-09-25 18:29:27
Python
Zakkaru, 2021-09-25 18:29:27

How to make the bot react to a message in the chat?

I make a chat bot
Type when a newcomer writes in the chat hello bot answered

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
FOUREX, 2021-09-25
@FOUREX

@bot.event
async def on_message(message):
    if "привет" in str(message).lower():
        await message.channel.send("Привет, друг")

Or use this method if the previous one didn't work:
@bot.event
async def on_message(message):
    if "привет" in str(message.content).lower():
        await message.channel.send("Привет, друг")

R
Ruslan Mandzyuk, 2021-09-25
@Ryslan_13

This should be message.content
the code

@bot.event
async def on_message(message):
    if "привет" in str(message.content).lower():
        await message.channel.send("Привет, друг")

After that, I got a bug that re-answers also to previous messages, in order to fix it, you need to remove it .lover()and everything will work well
here is the code without.lover()
@bot.event
async def on_message(message):
    if "привет" in str(message.content):
        await message.channel.send("Привет, друг")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question