Answer the question
In order to leave comments, you need to log in
The bot command is not working correctly, how to fix it?
I use the TELEBOT library.
Imported bs4 requests telebot.
The token was added and the handler too.
It does not give any errors when starting, all commands work except this one:
def getanekdot():
z=''
s=requests.get('http://anekdotme.ru/random')
b=bs4.BeautifulSoup(s.text, "html.parser")
p=b.select('.anekdot_text')
for x in p:
s=(x.getText().strip())
z=z+s+'\n\n'
return s
def handle_text(message):
msg=message.text
msg=msg.lower()
if message.text == 'анекдот':
bot.send_message(message.chat.id, getanekdot())
Answer the question
In order to leave comments, you need to log in
you forgot to write content_types, that's your mistake :)
import telebot
from telebot import types
import bs4
from bs4 import BeautifulSoup
import requests
def getanekdot():
z=''
s=requests.get('http://anekdotme.ru/random')
b=bs4.BeautifulSoup(s.text, "html.parser")
p=b.select('.anekdot_text')
for x in p:
s=(x.getText().strip())
z=z+s+'\n\n'
return s
@bot.message_handler(content_types='text')
def handle_text(message):
msg=message.text
msg=msg.lower()
if message.text == 'анекдот':
bot.send_message(message.chat.id, getanekdot())
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question