Answer the question
In order to leave comments, you need to log in
When the VK bot sends Russian characters, it replaces them with random Latin characters, how to fix it?
The bot should send annecdotes once an hour, and it takes annecdotes from a txt file. Here's what's in the txt file:
Here's what the bot sends: ?4??4??4??4??4??4??1? ?4??4??4??4??1? one . Here is the code:
import vk_api
import time
from vk_api import VkUpload
from vk_api.longpoll import VkLongPoll, VkEventType
global an1
global an2
global an3
global score
vk_session = vk_api.VkApi(token = '')
longpoll = VkLongPoll(vk_session)
upload = VkUpload(vk_session)
def sender(id, text):
vk_session.method('messages.send', {'chat_id' : id, 'message' : text, 'random_id' : 0,})
for event in longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW:
if event.to_me:
if event.from_chat:
msg = event.text.lower()
id = event.chat_id
if msg == 'привет':
while True:
score = 0
score += 1
an1 = open('C:/матвей/Вкбот/anekdot1.txt', 'rb')
an2 = open('C:/матвей/Вкбот/anekdot2.txt', 'rb')
an3 = open('C:/матвей/Вкбот/anekdot3.txt', 'rb')
sender(id, an1)
time.sleep(30)
if score == 1:
sender(id, an2)
score += 1
time.sleep(30)
if score == 2:
sender(id, an3)
time.sleep(30)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question