[你好,我想创建一个机器人来在 Twitter 上分享电报消息,但我收到错误消息 ( messages = bot.get_chat(chat_id=channel_id).get_last_message(count=10) AttributeError: 'coroutine' 对象没有属性 'get_last_message')
遵循代码。有人可以帮我吗?
import telegram
import tweepy
# Twitter API keys
consumer_key = "x"
consumer_secret = "x"
access_token = "x"
access_token_secret = "x"
# Telegram Bot API token
telegram_token = "x"
# Telegram chat ID to get messages from
channel_id = -1001679200115
# Authenticate with Twitter API
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
# Connect to Telegram Bot API
bot = telegram.Bot(token=telegram_token)
# Get the last 10 messages from the chat
messages = bot.get_chat(chat_id=channel_id).get_last_message(count=10)
# Share each message on Twitter
for message in messages:
tweet = f"{message.text}\n\n{message.link}"
api.update_status(tweet)
print(f"Tweet sent: {tweet}")