Импорт данных из файлов на Python
Я пишу бота с помощью pytelegrambotapi, у меня есть два файла main.py и command.py я хотел импортировать команды с файла command.py в main.py; если просто импортировать код выдаёт ошибку:
NameError: name 'bot' is not defined
а если я пишу переменную bot = telebot.TeleBot(config.TOKEN) в файл command.py, бот игнорирует импорт и не вызывает команды
Command.py
import telebot
@bot.message_handler(commands=['start'])
def start(message):
bot.send_message(message.chat.id, 'Привет, я бот')
@bot.message_handler(content_types=['text'])
def send_text(message):
if message.text.lower() == 'пинг':
bot.send_message(message.chat.id, 'Понг')
main.py
import telebot
import config
bot = telebot.TeleBot(config.TOKEN)
@bot.message_handler(commands=['help'])
def start(message):
bot.send_message(message.chat.id, 'Этот бот пока не предназначен что он будет делать')
if __name__ == "__main__":
bot.polling(none_stop=True)