1

我正在尝试在用户单击内联按钮后发送消息。它告诉我 chat_id 无效。当我把它拿出来时,它告诉我我必须把它包括在内。

每个其他按钮都可以正常工作,我在终端中收到回调

def on_callback_query(msg):
    query_id, from_id, query_data = telepot.glance(msg, flavor='callback_query')
    print('Callback Query:', query_id, from_id, query_data)
    
    if query_data == 'a':
        bot.sendMessage(chat_id, 'dsuhsdd')
        
4

2 回答 2

0

你不需要用全局范围使你的生活复杂化,因为在你的on_callback_query函数中你glanced查询所以你检索了 3 var:

query_id, from_id, query_data = telepot.glance(msg)

所以你只需要使用from_id表示发送chat_id查询的那个,所以:

def on_callback_query(msg):
    query_id, from_id, query_data = telepot.glance(msg, flavor='callback_query')
    print('Callback Query:', query_id, from_id, query_data)
    
    if query_data == 'a':
        bot.sendMessage(from_id, 'dsuhsdd')

当你浏览一条消息时,你有:

content_type, chat_type, chat_id = telepot.glance(msg)
#type of mesg, type of chat, chat identifier

但是当你浏览一个回调查询时:

query_id, from_id, query_data = telepot.glance(msg)
#query id, chat_id, txt data related to the query 
于 2021-03-02T07:04:59.223 回答
0

好的,我看到问题了,首先获取授权令牌>> https://telepot.readthedocs.io/en/latest/#get-a-token

接下来,添加这个以获取 chat_id

content_type, chat_type, chat_id = telepot.glance(msg)

您使用query_data作为对chat_id的引用

于 2021-03-01T19:18:56.000 回答