0

这是我的代码,我的 conf.py 文件只是我仔细检查过的 API 令牌和时区。我试图让我的机器人通过发送消息或照片来响应按钮单击。我知道我需要使用 sendPhoto 函数,但我不知道如何在回调中激活它

import sys
import time
import os
import telepot
from telepot.loop import MessageLoop
from telepot.namedtuple import InlineKeyboardMarkup, InlineKeyboardButton
from telepot.delegate import (
    per_chat_id, create_open, pave_event_space, include_callback_query_chat_id)

def on_chat_message(msg):
    content_type, chat_type, chat_id = telepot.glance(msg)

    if content_type == 'text':
        if msg['text'] == '/start':
           bot.sendMessage(chat_id, 'Welcome to @UK_Cali Teleshop\n      Created by JonSnow 2021',reply_markup = InlineKeyboardMarkup(inline_keyboard=[
                                    [InlineKeyboardButton(text="Feedback",callback_data='a'), InlineKeyboardButton(text="You",callback_data='b'),InlineKeyboardButton(text="PGP",callback_data='c'), InlineKeyboardButton(text="Cunt",callback_data='d')],
                                    [InlineKeyboardButton(text="Products",callback_data='e')]
                                ]
                                ))
        bot.sendMessage(chat_id, 'Quanti anni hai?', reply_markup=keyboard)
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(query_id, 'ddd')



    

bot = telepot.Bot('1646167995:AAGsOwfjcryYYkoah69QJ6XGA7koUywmuRk')
MessageLoop(bot, {'chat': on_chat_message,
                  'callback_query': on_callback_query}).run_as_thread()
print('Listening ...')

while 1:
    time.sleep(10)            











4

1 回答 1

0

您收到 400 错误,因为聊天 ID 不是quesry_id代表查询,而是from_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, 'ddd')
于 2021-03-02T06:59:06.727 回答