为什么我会收到错误 - TeleBot:“无限轮询异常:'list' 对象没有属性 'id' 特别是当我使用 new_chat_members 时?

问题描述 投票:0回答:1

我做了一个机器人并邀请它加入群组。

机器人是这个群的管理员,它不是私人的。我正在尝试让机器人向加入群组的用户发送私人消息。

问题是当我尝试这样做时,出现以下错误:

ERROR - TeleBot: "Infinity polling exception: 'list' object has no attribute 'id' 

我不知道那是什么意思,或者为什么我得到它或如何解决它。

这是我的代码:

import telebot

bot = telebot.TeleBot('here is bot token')

@bot.message_handler(content_types=["new_chat_members"])
def handler_new_member(message):
    first_name = message.new_chat_members[0].first_name
    bot.send_message(message.new_chat_members.id, "Something something".format(first_name))

bot.infinity_polling()

我试图让机器人向新成员发送私人消息,并希望它能阅读新成员的

id
,据我所知这是可能的。

我是

python
和电报 api 的新手。感谢您的帮助。

python telegram telebot
1个回答
0
投票

new_chat_members 似乎是一个实际列表。在第一行中,您使用列表索引来获取用户的名字。 Python 中的列表没有属性

id
。也许你的意思是
new_chat_members[index].id

© www.soinside.com 2019 - 2024. All rights reserved.