![](https://cdn.pixabay.com/photo/2016/11/19/14/00/code-1839406_960_720.jpg) (Image Source: [Pixabay](https://cdn.pixabay.com/photo/2016/11/19/14/00/code-1839406_960_720.jpg))

有没有好奇很多每日自动发的统计贴是怎么实现的?

如果没有,那不要往下看了:D

之前在怎么用JS写个召唤机器人?介绍过一个用于回复帖子的function:

1
2
3
4
5
6
7
8
9
10
11
12
13


steem.broadcast.comment (
private_posting_wif, //发帖密钥
parent_author, // 如果是发帖留空
parent_permlink, // 主标签
author, // 作者
permlink, // permlink
title, // 标题
body, // 内容
json_metadata // json
)

其实回复和发帖都用的是同一个function,区别在于一些参数的不同。

如果parent_author那一栏留空,说明是发帖。相反,如果parent_author那一栏留的是你要回复的作者的id,说明是回复。

如果你要发帖,可以这样写:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
const steem = require('steem');

steem.broadcast.comment(
"发帖密钥",
"", // 如果是发帖留空
"test",//主标签
"steem id",// 作者
"test-post",// permlink
"Test Post",//标题
"TEST",//内容
{
tags:['test'],//标签
app:'bot'
},
function(err, result) {
console.log(err, result);
});

运行以上代码后,会自动发一篇标题为“Test Post”,内容为“TEST”,标签为“test”的帖子。

把内容,标题,标签修改一下,一个自动发帖程序就这样建好了。是不是非常简单?


STEEM编程系列: