我正在使用 pytelegrambotapi,我想在命令后访问 word。
import telebot
wordlist = {}
bot = telebot.TeleBot('6515388014:AAEQLxcO6ndqHZJyulKPCVjkvnp2Zndqumg')
@bot.message_handler(commands=['start'])
def start(message):
bot.send_message(message.chat.id, 'Hi, this bot currently does nothing')
@bot.message_handler(commands=['add'])
def add_word(message, word):
bot.send_message(message.chat.id, f'Add the word {word} to the word list?')
@bot.message_handler()
def meme(message):
if message.text.lower() == 'мирон':
bot.send_message(message.chat.id, 'шашки')
bot.infinity_polling()
此代码不起作用。即使您在命令后写了一个单词(/add someword),您也会收到一条错误消息“仅给出了 1 个参数”所以我想知道是否有任何方法可以做到这一点。
我尝试向函数添加另一个参数,但这不起作用
您可以使用
message.text
访问命令后的文本。
试试这个:
@bot.message_handler(commands=['add'])
def add_word(message):
word = message.text.split(" ")[0]
bot.send_message(message.chat.id, f'Add the word {word} to the word list?')