為了遍歷松弛通道的消息,我編寫了以下內容:如果您只想遍歷 'text' 和 'ts' 怎么辦?我自己寫了以下內容,但出現錯誤TypeError:列表索引必須是整數或切片,而不是 strimport osfrom slack import WebClientfrom slack.errors import SlackApiErrorimport datetimeclient = WebClient(token=os.environ["SLACK_API_TOKEN"])channel_to_listen = os.environ['CHANNEL_TO_LISTEN']def main(): response = client.conversations_history(channel=channel_to_listen, limit= 10) messages = response['messages'] for message in messages: timestamp = messages['ts'] content = messages['text'] print(timestamp + " " + content)if __name__ == '__main__': main()我收到此錯誤:TypeError:列表索引必須是整數或切片,而不是 str如果我在消息中添加索引:messages = response['messages'][0]然后它將打印 10 次或與我在 limit 屬性中相同的時間戳和相同的文本相同的次數,這是有道理的。
我想遍歷python中松弛通道的消息和時間戳
慕田峪4524236
2022-10-18 19:44:11