Z
Z
zephyr_on_ice2019-10-21 15:02:37
JavaScript
zephyr_on_ice, 2019-10-21 15:02:37

Discord Bot, how to teach a bot to see a word in a message?

Good afternoon, I want to make the bot write a certain phrase if the message of any user contains a certain word. If the message starts with this word, then everything works.

client.on("message", (message) => {
  if (message.content.startsWith("слово")) {
    message.channel.send("ответ!");
  }
});

But if it is in the middle of the message, then this code no longer works.
client.on("message", (message) => {
  if (message.content.contains("кс")) {
    message.channel.send("кс не будет");
  }
});

Maybe I wrote stupidity, but please help

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2019-10-21
@Rsa97

https://developer.mozilla.org/en/docs/Web/JavaScript...

1
1 2, 2020-05-17
@weRifiCatoR

Here is the code:

import discord

client = discord.Client()

greeting = ('привет', 'пр', 'hello', 'hi', 'q', 'qq', 'privet')

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))

@client.event
async def on_message(message):
    if message.author == client.user:
        return

    if message.content.startswith( greeting ):
        await message.channel.send('Привет')

client.run()

The greeting contains the words that the bot will respond to (even if it sees them in the message), and in response to them says hello.
I think you understand!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question