Bot 无法处理与函数并行的多个请求 (discord.py)

Bot can't handle multiple request parallel to function (discord.py)

我正在尝试让我的 discord 机器人一次响应多个人。我的一个功能与 spacy 模块交互并处理大块文本。如果该函数被调用一次,然后再次调用,它最终会冻结我的机器人,因为它正在尝试处理第一个请求。

nlp = spacy.load("en_core_web_sm")

@bot.event
async def on_message(message):
   if message.content.startswith('!research'):

       doc = 'long paragraphs...'

      #Searches through doc for sentences relating to a word
       nlp(doc) #Takes time to process here
       results = textacy.extract.semistructured_statements(document, 'a word')

我的问题:我怎样才能运行一个类似的功能同时有多个请求或者我做错了什么?

我通过创建另一个异步函数解决了这个问题,它会在主事件被触发时被调用。

nlp = spacy.load("en_core_web_sm")

#Use async here!
async def researchCommand(doc, message): #Takes in doc and message so we can respond to author
    #Does processing here
    nlp(doc)


@bot.event
async def on_message(message): #Main function

    big_book = 'long paragraphs...'

    if message.content.startswith('!research'):
        await researchCommand(big_book, message)

现在您可以让多个请求与一个函数并行。