【问题标题】:How can I save this data to a txt using pyTelegramBotAPI如何使用 pyTelegramBotAPI 将此数据保存到 txt
【发布时间】:2019-10-14 04:47:16
【问题描述】:

这里有一个以

开头的嵌套结构
@bot.message_handler(content_types=["text"])
def handle_text (message, user_markup=None):

紧接着是嵌套结构,这个函数就在里面

def wallet(message):
    if message.text == 'Wallet NST':
       sent=bot.send_message(message.chat.id, """Crypto currency is an Ethereum token.
    NST Smart Contract Token Address is as follows:
    (0xD89040Ac9823B72F64d71f66Fa2DeAE7C8520671).
    Please make sure you are using the right smart contract or your funds may be irretrievably lost. \n
    INFORM YOUR WALLET NST(NEW SOLUTION ) :""")
      bot.register_next_step_handler(sent, salva)

def guard(message):
    archive=open('oriondb.txt', 'w')
    archive.write(int(messagefrom_user.id)  + message.from_user.username + message.chat.text )
    bot.send_message(message.chat.id, 'CARTEIRA SALVA COM SUCESSO!')
    bot.register_next_step_handler( handle_text)

我想将答案保存到 txt 文件或数据库中,如何使用 pytelegramBotAPI 做到这一点?

【问题讨论】:

    标签: python json telegram telegram-bot py-telegram-bot-api


    【解决方案1】:

    我认为它应该有效:

    @bot.message_handler(content_types=["text"])
    def wallet(m):
    cid = m.chat.id
    
    if m.text == 'Wallet NST':
       bot.register_next_step_handler(sent, salva)
       sent=bot.send_message(cid, """Crypto currency is an Ethereum token.
       NST Smart Contract Token Address is as follows:
       (0xD89040Ac9823B72F64d71f66Fa2DeAE7C8520671).
       Please make sure you are using the right smart contract or your funds may be 
       irretrievably lost. \n
       INFORM YOUR WALLET NST(NEW SOLUTION ) :""")
    
    
    archive=open('oriondb.txt', 'a')
    archive.append(str(cid)  + m.chat.username + m.chat.text )
    bot.send_message(cid, 'CARTEIRA SALVA COM SUCESSO!')
    

    【讨论】:

    • 您好,欢迎来到 stackoverflow,感谢您的回答。虽然这段代码可能会回答这个问题,但您是否可以考虑添加一些解释来说明您解决了什么问题,以及您是如何解决的?这将有助于未来的读者更好地理解您的答案并从中学习。
    猜你喜欢
    • 2015-08-04
    • 2012-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多