nextchar = string[idx]
IndexError: string index out of range
Проблема скорее всего в этом, если дословно, то вы вышли за рамки массива string 37 строка
vk_session = vk_api.VkApi(token=config.token)
longpoll = VkLongPoll(vk_session)
vk = vk_session.get_api()
while True:
for event in longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW and event.to_me:
print(event)