Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
名称错误:名称';startCommand';未定义-PYTHON 来自coinbase.wallet.client导入客户端 从电报输入模式 从telegram.ext导入CommandHandler、默认值、更新程序 COINBASE_键='xxxxxxxxxxx' COINBASE_SECRET='xxxxxxxxxxx' 电报令牌='XXXXXXXXXX' coinbase\u client=client(coinbase\u密钥,coinbase\u秘密) #如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu': 更新程序=更新程序(令牌=电报令牌,默认值=默认值(parse\u mode=ParseMode.HTML)) dispatcher=updater.dispatcher dispatcher.add_处理程序('start',startCommand)#通过/start访问 dispatcher.add_handler('alert',priceAlert)#通过/alert访问 updater.start_polling()#启动bot updater.idle()#等待脚本停止,这将停止bot def startCommand(更新,上下文): context.bot.send_message(chat_id=update.effective_chat.id,text='Hello there!') def priceAlert(更新,上下文): 如果len(context.args)>2: crypto=context.args[0]。上限() sign=context.args[1] price=context.args[2] context.job\u queue.run\u repeating(priceAlertCallback,interval=15,first=15,context=[crypto,sign,price,update.message.chat\u id]) 响应=f“⏳ 当{crypto}的价格达到{price}时,我将给您发送一条消息,\n“ 响应+=f“加密”的当前价格为{coinbase_client.get_spot_price(currency_pair=crypto+'-GBP')['amount']}” 其他: 答复='⚠️ 请提供密码和价格值:\n/price_alert{crypto code}{>/}{price}' context.bot.send_message(chat_id=update.effective_chat.id,text=response) def priceAlertCallback(上下文): crypto=context.job.context[0] sign=context.job.context[1] price=context.job.context[2] chat_id=context.job.context[3] 发送=错误 现货价格=coinbase客户机。获取现货价格(货币对=加密+'-GBP')['amount'] 如果符号=='_Python_Bots_Telegram_Python Telegram Bot - Fatal编程技术网

名称错误:名称';startCommand';未定义-PYTHON 来自coinbase.wallet.client导入客户端 从电报输入模式 从telegram.ext导入CommandHandler、默认值、更新程序 COINBASE_键='xxxxxxxxxxx' COINBASE_SECRET='xxxxxxxxxxx' 电报令牌='XXXXXXXXXX' coinbase\u client=client(coinbase\u密钥,coinbase\u秘密) #如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu': 更新程序=更新程序(令牌=电报令牌,默认值=默认值(parse\u mode=ParseMode.HTML)) dispatcher=updater.dispatcher dispatcher.add_处理程序('start',startCommand)#通过/start访问 dispatcher.add_handler('alert',priceAlert)#通过/alert访问 updater.start_polling()#启动bot updater.idle()#等待脚本停止,这将停止bot def startCommand(更新,上下文): context.bot.send_message(chat_id=update.effective_chat.id,text='Hello there!') def priceAlert(更新,上下文): 如果len(context.args)>2: crypto=context.args[0]。上限() sign=context.args[1] price=context.args[2] context.job\u queue.run\u repeating(priceAlertCallback,interval=15,first=15,context=[crypto,sign,price,update.message.chat\u id]) 响应=f“⏳ 当{crypto}的价格达到{price}时,我将给您发送一条消息,\n“ 响应+=f“加密”的当前价格为{coinbase_client.get_spot_price(currency_pair=crypto+'-GBP')['amount']}” 其他: 答复='⚠️ 请提供密码和价格值:\n/price_alert{crypto code}{>/}{price}' context.bot.send_message(chat_id=update.effective_chat.id,text=response) def priceAlertCallback(上下文): crypto=context.job.context[0] sign=context.job.context[1] price=context.job.context[2] chat_id=context.job.context[3] 发送=错误 现货价格=coinbase客户机。获取现货价格(货币对=加密+'-GBP')['amount'] 如果符号=='

名称错误:名称';startCommand';未定义-PYTHON 来自coinbase.wallet.client导入客户端 从电报输入模式 从telegram.ext导入CommandHandler、默认值、更新程序 COINBASE_键='xxxxxxxxxxx' COINBASE_SECRET='xxxxxxxxxxx' 电报令牌='XXXXXXXXXX' coinbase\u client=client(coinbase\u密钥,coinbase\u秘密) #如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu': 更新程序=更新程序(令牌=电报令牌,默认值=默认值(parse\u mode=ParseMode.HTML)) dispatcher=updater.dispatcher dispatcher.add_处理程序('start',startCommand)#通过/start访问 dispatcher.add_handler('alert',priceAlert)#通过/alert访问 updater.start_polling()#启动bot updater.idle()#等待脚本停止,这将停止bot def startCommand(更新,上下文): context.bot.send_message(chat_id=update.effective_chat.id,text='Hello there!') def priceAlert(更新,上下文): 如果len(context.args)>2: crypto=context.args[0]。上限() sign=context.args[1] price=context.args[2] context.job\u queue.run\u repeating(priceAlertCallback,interval=15,first=15,context=[crypto,sign,price,update.message.chat\u id]) 响应=f“⏳ 当{crypto}的价格达到{price}时,我将给您发送一条消息,\n“ 响应+=f“加密”的当前价格为{coinbase_client.get_spot_price(currency_pair=crypto+'-GBP')['amount']}” 其他: 答复='⚠️ 请提供密码和价格值:\n/price_alert{crypto code}{>/}{price}' context.bot.send_message(chat_id=update.effective_chat.id,text=response) def priceAlertCallback(上下文): crypto=context.job.context[0] sign=context.job.context[1] price=context.job.context[2] chat_id=context.job.context[3] 发送=错误 现货价格=coinbase客户机。获取现货价格(货币对=加密+'-GBP')['amount'] 如果符号==',python,bots,telegram,python-telegram-bot,Python,Bots,Telegram,Python Telegram Bot,尝试 您还需要添加两个函数所需的两个参数 dispatcher.add_handler('start', startCommand(update, context)) dispatcher.add_handler('alert', startCommand(update, context)) 我不太确定这两个函数接收的数据是什么,但我猜它是bot返回的任何数据。Python自上而下地读取文件。因此,当您调用dispatcher.add\u handler('start',startComman

尝试

您还需要添加两个函数所需的两个参数

dispatcher.add_handler('start', startCommand(update, context))
dispatcher.add_handler('alert', startCommand(update, context))

我不太确定这两个函数接收的数据是什么,但我猜它是bot返回的任何数据。

Python自上而下地读取文件。因此,当您调用
dispatcher.add\u handler('start',startCommand)
时,函数
startCommand
还不知道。移动部件

updater = Updater(token=TELEGRAM_TOKEN, defaults=Defaults(parse_mode=ParseMode.HTML))
dispatcher = updater.dispatcher
dispatcher.add_handler('start', startCommand) # Accessed via /start
dispatcher.add_handler('alert', priceAlert) # Accessed via /alert

updater.start_polling() # Start the bot

updater.idle() # Wait for the script to be stopped, this will stop the bot
下面是回调定义

除此之外,
add\u handler
需要一个
handler
作为参数,在您的例子中类似于
add\u handler(commandhandler('start',startCommand)
。请参见以及



免责声明:我是
python Telegrame bot
库的当前维护者。

在定义函数之前,您不能引用函数名。请将函数定义放在开头。我知道您说过您尝试更改位置,但一定没有将其放在正确的位置。请重试。是否尝试移动所有函数导入后,在dispatcher.add_handler('start',startCommand)#中的文件“bot.py”,第59行,通过/start File“/home/ishaan/.local/lib/python3.8/site packages/telegram/ext/dispatcher.py”访问,在add_handler raise TypeError(f'handler不是{handler.\u name_u}的实例)第501行TypeError:handler不是handler的实例。如果在导入后移动,则会显示此错误。它仍然显示相同的错误:(这不是
add\u handler
的工作方式。有关详细信息,请参阅。
updater = Updater(token=TELEGRAM_TOKEN, defaults=Defaults(parse_mode=ParseMode.HTML))
dispatcher = updater.dispatcher
dispatcher.add_handler('start', startCommand) # Accessed via /start
dispatcher.add_handler('alert', priceAlert) # Accessed via /alert

updater.start_polling() # Start the bot

updater.idle() # Wait for the script to be stopped, this will stop the bot