*
import responses
API_KEY = '**********************************'
# Set up the logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
logging.info('Starting Bot...')
def start_command(update, context):
update.message.reply_text('Hello there! What would you like today?')
def help_command(update, context):
update.message.reply_text('Try typing anything and I will do my best to respond!')
def custom_command(update, context):
update.message.reply_text('This is a custom command, you can add whatever text you want here.')
def handle_message(update, context):
text = str(update.message.text).lower()
logging.info(f'User ({update.message.chat.id}) says: {text}')
# Bot response
response = responses.get_response(text)
update.message.reply_text(response)
def error(update, context):
# Logs errors
logging.error(f'Update {update} caused error {context.error}')
# Run the programme
if name == 'main':
updater = Updater(API_KEY, use_context=True)
dp = updater.dispatcher
# Commands
dp.add_handler(CommandHandler('start', start_command))
dp.add_handler(CommandHandler('help', help_command))
dp.add_handler(CommandHandler('custom', custom_command))
# Messages
dp.add_handler(MessageHandler(Filters.text, handle_message))
# Log all errors
dp.add_error_handler(error)
# Run the bot
updater.start_polling(1.0)
updater.idle()
My error after i send a message to my bot:
2021-08-05 20:25:19,172 - root - ERROR - Update {'message': {'entities': [], 'text': 'no', 'supergroup_chat_created': False, 'message_id': 19, 'chat': {'first_name': '****', 'last_name': '***', 'id': 619472808, 'type': 'private'}, 'delete_chat_photo': False, 'photo': [], 'date': 1628175322, 'group_chat_created': False, 'new_chat_photo': [], 'new_chat_members': [], 'caption_entities': [], 'channel_chat_created': False, 'from': {'first_name': '****', 'id': 619472808, 'language_code': 'en', 'is_bot': False, 'last_name': '****'}}, 'update_id': 837890579} caused error module 'responses' has no attribute 'get_response'
try from responses import get_response Then in the code use response = get_response(text)
Обсуждают сегодня