python - 如何使用 pyTelegramBotAPI 将此数据保存到 txt
问题描述
在这里有一个嵌套结构,它开始于
@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 执行此操作?
解决方案
我认为它应该工作:
@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!')
推荐阅读
- rust - Rust:为什么编译器会将 !!value 翻译为 value?
- java - FutureTask 获取与运行,任务永远不会完成
- django - 多次导入同一文件时Django导入导出重复行
- git - 从 git bundle 中提取部分内容
- java - 有什么办法可以延迟第三方应用的启动吗?
- alfresco - 将 Alfresco 共享中的文件夹模板限制为特定站点
- jquery - 滚动时,数据切换下拉菜单保持固定在页面顶部
- google-sheets - 表格脚本:为什么我的脚本停止工作?
- scala - 加载 Spark-nlp pretrainedPipeline 时出错
- python - 用于估计圆柱体(半径和高度)的构建类