So I'm new at making a telegram bot, I want to have like the botfather
:
user: create bot
bot: provide name for your bot
user: foo bot
then the user text is used in the future.
I have a simple sample bot which defines a word that the user provide
user:/define internet
bot: defines the term
but I want to recreate it to
user:/define
bot: please send the word you want to define
user: internet
bot: defines the term
user: ....
I'm using pyTelegramBotAPI
Here is my code
@bot.message_handler(commands=['define'])
def dictionary(message):
user_message = message.text
msg = user_message.split(' ')
if len(msg) != 1:
try:
word = msg[1]
botmsg = bot.send_message(message.chat.id, 'Finding the word in the dictionary')
resp = requests.get(DICT_URL + word)
respData = resp.json()
pof = respData[0]['meanings'][0]['partOfSpeech']
print(pof)
defi = respData[0]['meanings'][0]['definitions'][0]['definition']
print(defi)
bot.send_message(message.chat.id, text=f'*Word:* {word} \n\n *Part Of Speech: *{pof} \n\n *Definition: *{defi}', parse_mode='Markdown')
bot.delete_message(message.chat.id, botmsg.message_id)
except:
bot.send_message(message.chat.id, "Couldn't find in the dictionary.")
else:
bot.send_message(message.chat.id, 'Please input a word to define.')