vkonakte的bot不应答消息

68de4m5k  于 2021-07-13  发布在  Java
关注(0)|答案(0)|浏览(201)

没有显示任何错误,尽管bot没有应答消息。令牌和组id正确。

import vk_api
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
from data import token, group_id
from random import random

vk_session = vk_api.VkApi(token=token)
vk = vk_session.get_api()
longpoll = VkBotLongPoll(vk_session, group_id)

def sender(id, text):
    vk_session.method('messages.send', {'user_id': id, 'message': text, 'random_id': 0})

while True:
    longpoll = VkBotLongPoll(vk_session, group_id)
    for event in longpoll.listen():
        if event.type == VkBotEventType.MESSAGE_NEW:
            msg = event.object.message['text'].lower()
            if event.to_me:
                id = event.user_id

                if msg == 'hi':
                    sender(id, 'hello')

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题