python 使用Slack的files_upload_v2()通过DM发送文件时出错

5f0d552i  于 2023-10-15  发布在  Python
关注(0)|答案(1)|浏览(81)

Slack建议从files_upload()迁移到files_upload_v2(),以获得与大型文件相关的稳定性。但是,这一更改意味着您不能再使用client.files_upload_v2(channel='@user.name', file=file)之类的东西。您只能发送到由通道ID引用的通道。有没有一种方法可以使用v2功能来发送文件作为DM(这将出现在机器人的消息通道中)?关于v2的详细说明是here

from slack_sdk import WebClient
token = MY_TOKEN
client = WebClient(token=token)
# works
response = client.files_upload(channels="@user.name", file="myfile.csv")

# fails
response = client.files_upload_v2(channels="@user.name", file="myfile.csv")

错误:

SlackApiError: The request to the Slack API failed. (url: https://www.slack.com/api/files.completeUploadExternal)
    The server responded with: {'ok': False, 'error': 'invalid_arguments', 'response_metadata': {'messages': ['[ERROR] input must match regex pattern: ^[CGD][A-Z0-9]{8,}$ [json-pointer:/channel_id]']}}
siv3szwd

siv3szwd1#

您没有正确调用用户名,请尝试<@{username}>

相关问题