-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeneral
28 lines (23 loc) · 1.11 KB
/
general
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import telebot
from langdetect import detect
import random
# Замените эту строку вашим токеном бота
TOKEN = 'YOUR_BOT_TOKEN'
bot = telebot.TeleBot(TOKEN)
@bot.message_handler(commands=['start'])
def start_message(message):
bot.send_message(message.chat.id, 'Привет! Я могу определить язык вашего сообщения и ответить случайным сообщением.')
@bot.message_handler(content_types=['text'])
def detect_language(message):
try:
language = detect(message.text)
responses = {
'en': ['Hello!', 'Hi!', 'Hey!'],
'ru': ['Привет!', 'Здравствуйте!', 'Хей!'],
# Добавьте больше языков и ответов по мере необходимости
}
response = random.choice(responses.get(language, ['Я не понял ваш язык.']))
bot.send_message(message.chat.id, response)
except Exception as e:
bot.send_message(message.chat.id, f'Ошибка: {str(e)}')
bot.polling(none_stop=True, interval=0)