通过 R 向 Discord 机器人发送复杂的消息

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

我正在使用 httr 包中的 POST 通过不和谐机器人发送消息作为大型脚本更新,并且我想让这些消息比当前更复杂一点。

我的问题是以下消息仅返回相同的单个单词“try”。

library(httr)

POST(url = "<mywebhook>",
     body = list(content = "try"),
     encode = "json")

POST(url = "<mywebhook>",
     body = list(content = "try",
                 embed = list(title = "this is a title",
                              ThumbnailUrl = "<someimage.png>")),
     encode = "json")

我的粗略理解是,我可以通过一系列嵌入的嵌套列表来模仿 json 格式,但这似乎并非如此。

理想情况下,我想设置嵌入,以便我可以在运行时将更新的绘图发送到服务器,或者以编程方式生成文本字符串以提供有关脚本活动的信息。

r json discord
1个回答
0
投票

这是一个拼写错误。正确的元素是

embeds
不是
embed
,它是对象数组,所以在 R 中它应该是列表的列表:

POST(
    url = "<mywebhook>"
    ,body = list(
        content = "try"
        ,embeds = list(
            list(
                title = "this is a title"
                ,ThumbnailUrl = "<someimage.png>"
            )
        )
    )
    ,encode = "json"
)
© www.soinside.com 2019 - 2024. All rights reserved.