如何在 Python 中尽快从不和谐消息中检索特定关键字

我想在 Python 中尽快从不和谐消息中获取特定关键字,我目前正在使用一个请求,但问题是实现和获取新消息需要太多时间(需要花费太多时间) 200-500 毫秒接收消息),我相信有更好的方法。

def retrieve_messages(channelid):
     while True:
        ##DISCORD   
        headers = {'authorization':""}
        r= requests.get('https://discord.com/api/v9/channels/xxxxxxxxxxxxxxx/messages',headers=headers)
        jsonn = json.loads(r.text)
     
        for value in jsonn:       
            s1=str(value['content'])
            s2=(re.findall('code:(0x......................)',s1))
            if s2 !=[]:
                print(s2)
retrieve_messages('')
zhouyoulie04 回答:如何在 Python 中尽快从不和谐消息中检索特定关键字

根据参考,从端点返回的默认消息数为 50(链接:https://discord.com/developers/docs/resources/channel#get-channel-messages)。使用限制参数应该可能只得到 1 或 5,这应该可以限制检索消息所需的时间以及循环遍历它们所需的时间。

本文链接:https://www.f2er.com/3825.html

大家都在问