【问题标题】:How can I solve the problem with ReplyKeyboardButton?如何解决ReplyKeyboardButton 的问题?
【发布时间】:2019-12-28 17:12:07
【问题描述】:

ReplyKeyboardButton 方法有问题。

我尝试从 aiogram 连接模块,我尝试从远程机器人获取类型,我尝试仅使用一个模块(远程机器人)

import telebot
#from aiogram.types import ReplyKeyboardRemove, \
#ReplyKeyboardMarkup, KeyboardButton, \
    #InlineKeyboardMarkup, InlineKeyboardButton

token = 'mytoken'
bot = telebot.TeleBot(token)

#keyboard1 = telebot.types.ReplyKeyboardMarkup()
#keyboard1.row('Категории', 'Купить приватку', 'Что дает приватка?')
button_qiwi = ReplyKeyboardButton('QIWI')
button_sber = ReplyKeyboardButton('Сбербанк')
button_categories = ReplyKeyboardButton('Категории')
button_privat = ReplyKeyboardButton('Купить приватку')
button_whatis = ReplyKeyboardButton('Что дает приватка?')
button_cancel = ReplyKeyboardButton('Назад')

markup_start = ReplyKeyboardMarkup().row(
    button_categories, button_privat, button_whatis
)

markup_pay = ReplyKeyboardMarkup().row(
    button_qiwi, button_sber, button_cancel
)


@bot.message_handler(commands=['start'])
def start_message(message):
    bot.send_message(message.chat.id, 'Привет! Чтобы ты взаимодействовал с     ботом, тебе нужно зайти в кнопки.', reply_markup=markup_start)

@bot.message_handler(content_types=['sticker'])
def sticker_id(message):
    print(message)

@bot.message_handler(content_types=['text'])
def send_text(message):
    if message.text.lower() == 'категории':
        bot.send_message(message.chat.id, '123')
    elif message.text.lower() == 'купить приватку':
        bot.send_sticker(message.chat.id, 'CAADAgADZgkAAnlc4gmfCor5YbYYRAI')
        bot.send_message(message.chat.id, 'Хорошо! Приватка стоит 450 рублей. Оплатить можно через QIWI и через Сбербанк. Как удобней?', reply_markup = markup_pay)
        if message.text.lower() == 'Сбербанк':
            bot.send_text(message.chat.id, '123')
        if message.text.lower() == 'QIWI':
            bot.send_text(message.chat.id, '123')
        elif message.text.lower() == 'Назад':
            bot.send_sticker(message.chat.id,'',reply_markup = markup_start)
        else:
            bot.send_message(message.chat.id, 'Ой! Что-то пошло не так((')
    elif message.text.lower() == 'что дает приватка?':
        bot.send_message(message.chat.id, 'Доступ ко всем категориям, Уникальный контент')
    else:
        bot.send_message(message.chat.id, 'Неизвестная команда')

bot.polling()

这是输出:

Traceback(最近一次调用最后一次): 文件“C:/Users/yaros/Desktop/bot/bot.py”,第 11 行,在 button_qiwi = ReplyKeyboardButton('QIWI') NameError:名称“ReplyKeyboardButton”未定义

进程以退出代码 1 结束。

【问题讨论】:

  • 您可能必须在某个地方 import 它 - 查看其余代码,from aiogram.types import ReplyKeyboardButton 不是您需要的吗?
  • 我不得不删除前缀回复

标签: python python-telegram-bot


【解决方案1】:

嗯,你需要markup = types.ReplyKeyboardRemove(),而你只有markup_pay = ReplyKeyboardMarkup().row。我的意思是你忘记了types.,你需要from telebot import types

【讨论】:

    猜你喜欢
    • 2011-10-25
    • 2018-07-07
    • 2019-01-30
    • 2019-09-21
    • 2021-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多