【发布时间】:2021-06-06 14:49:39
【问题描述】:
这个项目是在 pyTelegramBotAPI 模块上开发的。 我需要做的是检查机器人是否已经在私人聊天中启动,因为这主要是在一个群组上运行的。
如果我尝试从群组向尚未启动机器人的玩家发送消息,我的应用会崩溃:
ERROR - TeleBot: "A request to the Telegram API was unsuccessful.
Error code: 403. Description: Forbidden: bot was blocked by the user"
@bot.message_handler(commands=['inventory'])
def handle_command_adminwindow(message):
# add column for each 7 elements in matrix
rootInventory = ref.child("inventory").get()
userPool = []
userId = message.from_user.id
items = []
for i in rootInventory:
userPool.append(i)
userId = f"{userId}"
if userId in userPool:
refItems = ref.child("inventory").child(userId).get()
for i in refItems:
items.append(i)
nitem = len(items)
while(nitem%7!=0):
nitem += 1
#load query witj new data
inventory(message, items)
然后我宣布我的电话:
def inventario(message, items):
# List object downloaded from firebase and ready for call actions
markup = InlineKeyboardMarkup()
listFruits = ["apple", "banana", "strawberry", "berries", "kiwi", "peach"]
idGamer = message.from_user.id
idMsg = message.message_id
i = 0
while i < len(items):
row = []
if items[i] in listFruits:
row.append(InlineKeyboardButton(text=items[i], callback_data=f"{idGamer}-cb_f{items[i]}"))
else:
row.append(InlineKeyboardButton(text=items[i], callback_data=f"cb_other"))
i += 1
if items[i] in listFruits:
row.append(InlineKeyboardButton(text=items[i], callback_data=f"{idGamer}-cb_f{items[i]}"))
else:
row.append(InlineKeyboardButton(text=items[i], callback_data=f"cb_other"))
i += 1
markup.row(*row)
bot.send_message(message.chat.id, "You can now check your inventory in pvt\nlink to pvp chat with bot")
bot.send_message(message.from_user.id, 'Inventory', reply_markup=markup)
【问题讨论】:
标签: python telegram py-telegram-bot-api