[英]Why can't my bot reply to telegram messages anymore?
我有 2 個群聊,GC A 和 B。該機器人是兩者的管理員,只是將新消息轉發到另一個組,然后留下諸如“轉發謝謝”之類的回復。 在原始組中進行通知。
在 GC A 中,機器人能夠很好地回復新消息,但是機器人無法回復 GC A 中的消息。
我不禁認為這是一個錯誤,因為機器人在我第一次運行它時運行良好,但在編輯代碼以添加新功能后,它不再回復。
這里發生了什么,我該如何解決?
作為獎勵:機器人能夠注意到消息何時被編輯並回復。 這部分在兩個組中仍然有效,但是當我只是發送一條新消息時它不起作用。
我完全替換了機器人,就像我刪除它並制作了一個新的一樣。 仍然沒有工作
我之前遇到過同樣的問題,剛剛創建了一個新的群聊,但我現在不能這樣做。
# -*- coding: utf-8 -*-
"""
Created on Wed Dec 15 16:28:19 2021
@author: erdze
"""
from datetime import datetime
import telegram
from telegram import Update
import logging
from telegram.ext import Updater, CallbackContext, CommandHandler, MessageHandler, Filters
from CONSTANTS import "some stuff"
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
bot = telegram.Bot(TOKEN_TEST)
updater = Updater(TOKEN_TEST, use_context=True)
dispatcher = updater.dispatcher
job = updater.job_queue
def status(update: Update, context: CallbackContext):
context.bot.send_message(chat_id=update.effective_chat.id, text="I am alive. Thanks!")
def test(update: Update, context: CallbackContext):
context.bot.send_message(chat_id=USER_TEST, text="I'm a bot not a person")
#forward to group "RECEIVER"
def forward_edits_to_group(update: Update, context: CallbackContext):
check = 0
#this section breaks up the sentence into individual words and makes the lowercase
sent_message = update.edited_message.text
sent_message = sent_message.lower()
sent_message = sent_message.split()
for keyword in keyword_list:
if keyword in sent_message:# checks if message contains keyword
check += 1
if check == 3:
bot.forward_message(chat_id = TEST_RECEIVER,
from_chat_id=update.edited_message.chat_id,
message_id=update.edited_message.message_id)
context.bot.send_message(chat_id=TEST_RECEIVER, text="Forwarded thanks :D")
check = 0
#forward to group "RECEIVER"
def forward_to_group(update: Update, context: CallbackContext):
check = 0
#this section breaks up the sentence into individual words and makes the lowercase
sent_message = update.message.text
sent_message = sent_message.lower()
sent_message = sent_message.split()
for keyword in keyword_list:
if keyword in sent_message:# checks if message contains keyword
check += 1
if check == 3:
bot.forward_message(chat_id = TEST_RECEIVER,
from_chat_id=update.message.chat_id,
message_id=update.message.message_id)
context.bot.send_message(chat_id=TEST_RECEIVER, text="Forwarded thanks :D")
check = 0
#forward to group "karama dj"
def forward_edits_to_dj(update: Update, context: CallbackContext):
check = 0
#this section breaks up the sentence into individual words and makes the lowercase
sent_message = update.edited_message.text
sent_message = sent_message.lower()
sent_message = sent_message.split()
for keyword in keyword_list:
if keyword in sent_message:# checks if message contains keyword
check += 1
if check == 3:
bot.forward_message(chat_id = "a chat id",
from_chat_id=update.edited_message.chat_id,
message_id=update.edited_message.message_id)
context.bot.send_message(chat_id="a chat id", text="Forwarded thanks :D")
check = 0
#forward to group "karama dj"
def forward_to_dj(update: Update, context: CallbackContext):
check = 0
#this section breaks up the sentence into individual words and makes the lowercase
sent_message = update.message.text
sent_message = sent_message.lower()
sent_message = sent_message.split()
for keyword in keyword_list:
if keyword in sent_message:# checks if message contains keyword
check += 1
if check == 3:
bot.forward_message(chat_id = "a chat id",
from_chat_id=update.message.chat_id,
message_id=update.message.message_id)
context.bot.send_message(chat_id="a chat id", text="Forwarded thanks :D")
check = 0
#forward to group "g4 strong"
def forward_edits_to_g4(update: Update, context: CallbackContext):
check = 0
#this section breaks up the sentence into individual words and makes the lowercase
sent_message = update.edited_message.text
sent_message = sent_message.lower()
sent_message = sent_message.split()
for keyword in keyword_list:
if keyword in sent_message:# checks if message contains keyword
check += 1
if check == 3:
bot.forward_message(chat_id = "a chat id",
from_chat_id=update.edited_message.chat_id,
message_id=update.edited_message.message_id)
bot.forward_message(chat_id = "a chat id",
from_chat_id=update.edited_message.chat_id,
message_id=update.edited_message.message_id)
context.bot.send_message(chat_id=G4, text="Forwarded thanks :D")
check = 0
#forward to group "g4 strong"
def forward_to_g4(update: Update, context: CallbackContext):
check = 0
#this section breaks up the sentence into individual words and makes the lowercase
sent_message = update.message.text
sent_message = sent_message.lower()
sent_message = sent_message.split()
for keyword in keyword_list:
if keyword in sent_message:# checks if message contains keyword
check += 1
if check == 3:
bot.forward_message(chat_id = "a chat id",
from_chat_id=update.message.chat_id,
message_id=update.message.message_id)
bot.forward_message(chat_id = "a chat id",
from_chat_id=update.message.chat_id,
message_id=update.message.message_id)
context.bot.send_message(chat_id=G4, text="Forwarded thanks :D")
check = 0
#checks what the time is every second
def callback_second(context: telegram.ext.CallbackContext):
current_time = datetime.now()
time_now = current_time.strftime("%H,%M,%S")
day = datetime.today().weekday()
gawain_remind_times = [6,0,2,5]
#sends gawain link at 9:50pm everyday
if time_now == "21,50,00":
context.bot.send_message(chat_id=G4, text=text)
context.bot.send_message(chat_id=G4, text=text)
#reminder about gawain at 1pm everyday
if time_now == "13,00,00" and day in gawain_remind_times:
context.bot.send_message(chat_id=G4, text=text)
context.bot.send_message(chat_id=G4, text=text)
#ask who attended gawain at 9:30pm
if time_now == "21,30,00" and day in gawain_remind_times:
context.bot.send_message(chat_id=G4, text=text)
context.bot.send_message(chat_id=G4, text=text)
#ask who attended gawain at 8:30pm
if time_now == "20,30,00" and day in gawain_remind_times:
context.bot.send_message(chat_id=G4, text=text)
context.bot.send_message(chat_id=G4, text=text)
#ask who attended gawain at 7:30pm
if time_now == "19,30,00" and day in gawain_remind_times:
context.bot.send_message(chat_id=G4, text=text)
context.bot.send_message(chat_id=G4, text=text)
def main():
#checks time every second
job_minute = job.run_repeating(callback_second, interval=1)
#status command
start_handler = CommandHandler('status', status)
dispatcher.add_handler(start_handler)
#tester command
test_handler = CommandHandler('test', test)
dispatcher.add_handler(test_handler)
#forwards edited messages from group TESTER
test_forward_edits_handler = MessageHandler(Filters.chat(TEST_SENDER) & Filters.update.edited_message, forward_edits_to_group)
dispatcher.add_handler(test_forward_edits_handler)
#forwards messages from group TESTER
test_forward_handler = MessageHandler(Filters.chat(TEST_SENDER), forward_to_group)
dispatcher.add_handler(test_forward_handler)
#forwards edited messages from group
dj_forward_edits_handler = MessageHandler(Filters.chat(KARAMA_DJ) & Filters.update.edited_message, forward_edits_to_dj)
dispatcher.add_handler(dj_forward_edits_handler)
#forwards messages from group
dj_forward_handler = MessageHandler(Filters.chat(KARAMA_DJ), forward_to_dj)
dispatcher.add_handler(dj_forward_handler)
#forwards edited messages from group
g4_forward_edits_handler = MessageHandler(Filters.chat(G4) & Filters.update.edited_message, forward_edits_to_g4)
dispatcher.add_handler(g4_forward_edits_handler)
#forwards messages from group
g4_forward_handler = MessageHandler(Filters.chat(G4), forward_to_g4)
dispatcher.add_handler(g4_forward_handler)
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()
在沒有更改任何代碼的情況下離開它一段時間后,它現在可以工作了。 我不知道為什么會發生這種情況,但我將把它留在這里以供將來參考。
注:不知道是不是問題; 1. ptb 中的錯誤,2. 電報延遲或錯誤,以及 3. 我自己的無能。 但我很新,所以這可能是我的無能
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.