gpt4 book ai didi

python - 尝试在 python-slackclient 中使用@channel、@here 和@user

转载 作者:行者123 更新时间:2023-12-05 03:51:40 25 4
gpt4 key购买 nike

我尝试使用@channel、@here 和@user 发送消息,但它们都是以文本形式发送的。

enter image description here

这是代码....

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 DocsAPI 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com