我尝试使用@channel、@here 和@user 发送消息,但它们都是以文本形式发送的。
这是代码....
import os
from slack import WebClient
from slack.errors import SlackApiError
client = WebClient(token='xoxb-**************************')
try:
response = client.chat_postMessage(
channel='#prueba',
text="@channel Hello world!",
as_user=False)
assert response["message"]["text"] == "Hello world!"
except SlackApiError as e:
# You will get a SlackApiError if "ok" is False
assert e.response["ok"] is False
assert e.response["error"] # str like 'invalid_auth', 'channel_not_found'
print(f"Got an error: {e.response['error']}")
我都读过 PythonSlackclient Docs和 API Docs ,但我找不到广播我的消息或如何提及某人的选项。
最佳答案
您需要将代码更改为
response = client.chat_postMessage(
channel='#prueba',
text="<!channel> Hello world!",
as_user=False)
assert response["message"]["text"] == "@channel Hello world!"
Slack API 拥有最好的文档之一,可以开始链接用户 read this
关于python - 尝试在 python-slackclient 中使用@channel、@here 和@user,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62706429/