实现字典搜索的电报机器人

2024-06-28 16:12:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在创建一个在在线词典中搜索单词的telegram bot,当我需要在telegram中创建用于在字典中搜索的命令时,问题就来了,现在我有了这个:

from rae import Drae
drae = Drae()

  if text.startswith('/'):
     if text =='/define':
        drae.search(u' ')  # The problem is here, I don't know how to implement the command and the word who the client wants to search.
        setEnabled(chat_id, True)

Tags: thetotexthttpsgithubcomsearchif
1条回答
网友
1楼 · 发布于 2024-06-28 16:12:35

这个怎么样。在

from rae import Drae

drae = Drae()

if text.startswith('/'):
  if text.startswith('/define'):
    try:
      [command, data] = text.split(' ',1)
    except:
      send('Write: /define <word>')
    meanings = drae.search(data) 
    reply(str(meanings)) 
    setEnabled(chat_id, True)

相关问题 更多 >