Search on blog:

Python How to process all messages in Discord.

bot.commands is extension (you import it from discord.ext) which helps to make code simpler - ie. it automatically recognize if message has prefix, it splits message to words, and it assigns command to function.

But you don't have to use it. You can use event on_message to get full text from user and then you can process it on you own. It means you can compare with pattern/regex, lemmatize, use with NLTK, etc. But it also means you have to on your own split message to words and recognize prefix (if you want to run code only when command has prefix).

import discord
import random
import shlex  # to split `say "A B C"` as two elements `say` `"A B C"`

data = {
    'hello': ['Hello World!', 'Good Morning Vietnam!', 'Good Day My Lord']

client = discord.Client()

async def on_message(message):
    # ignore messages made by the bot
    if == client.user:

    # preprocessing message
    text = message.content.lower()
    #words = text.split(' ')        # 'say "A B C"' -> ['say', '"A', 'B', 'C"']
    words = list(shlex.shlex(text)) # 'say "A B C"' -> ['say', '"A B C"'] 
    if not words:
        await"I don't understand you: " + str(words))

    first_word = words[0] 

    # only message which starts with prefix `$`
    #if not text.startswith('$'):
    #    return 

    found = False

    # compare message with dictionary
    for word, answers in data.items():
        #if text.startswith(word): # will treat `hellowin` like `hello`
        if first_word == word:     # will skip `hellowin` 
            found = True
            selected = random.choice(answers) 

    if not found:
        await"I don't understand you: " + str(words))"MY_TOKEN")


Stackoverflow How do I make my discord bot understand my word list? And execute it?

Example in documentation in Quickstart

If you like it
Buy a Coffee