机器人消息电报bot之后,如何从用户那里获取消息更新
因此,我是新手制作电报机器人的,我想拥有 botfather
:
user: create bot
bot: provide name for your bot
user: foo bot
将来使用用户文本。
我有一个简单的示例机器人,该机器人定义了用户提供的单词
user:/define internet
bot: defines the term
,但我想将其重新创建为
user:/define
bot: please send the word you want to define
user: internet
bot: defines the term
user: ....
这是我的代码
@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.')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了感谢@furas的答案,@furas帮助他的评论
无法与我同样的问题,这是代码。
I've found the answer thanks to @furas who helped with his comments
incase someone has the same problem with me here's the code.