[Solved] How to make bot respond to a certain msg?


You can do this one of two ways, either with the commands extension, or within the on_message event.

Below is an example of how you can do this. With this example, when a user types “!ping” the bot will respond with “Pong”. If a message contains the word “foo”, then the bot will respond with “bar”.

from discord.ext import commands

client = commands.Bot(command_prefix='!')

@client.event
async def on_ready():
    print('client ready')

@client.command()
async def ping():
    await client.say('Pong')

@client.event
async def on_message(message):
    if client.user.id != message.author.id:
        if 'foo' in message.content:
            await client.send_message(message.channel, 'bar')

    await client.process_commands(message)

client.run('TOKEN')

4

solved How to make bot respond to a certain msg?