Skip to content

Commit 7efd8d2

Browse files
authored
Update bot.js
1 parent 67735c2 commit 7efd8d2

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

bot/bot.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ const twit = new Twit(require("./config.js"));
88
const mediaArtsSearch = { q: "#MeetMaye", count: 100, result_type: "recent" };
99

1010
// This function finds the latest tweet with the MeetMaye hashtag and retweets.
11-
const retweetLatest = () => {
12-
twit.get("search/tweets", mediaArtsSearch, (error, data) => {
11+
const retweetLatest = async() => {
12+
try {
13+
twit.get("search/tweets", mediaArtsSearch, (error, data) => {
1314
// If our search request to the server had no errors...
1415
if (error) {
1516
// However, if our original search request had an error, we want to print it out here...
@@ -19,16 +20,20 @@ const retweetLatest = () => {
1920
const retweetId = data.statuses[0].id_str;
2021
// Tell Twitter we want to retweet it...
2122
twit.post("statuses/retweet/" + retweetId, {}, (error, response) => {
22-
if (response) {
23-
console.log("Success! Your bot has retweeted something.");
24-
}
23+
2524
// If there was an error with our Twitter call, we print it out here...
2625
if (error) {
2726
console.log(error.message);
27+
} else if (response) {
28+
console.log("Success! Retweeted!");
2829
}
2930
});
3031
}
3132
});
33+
} catch(error) {
34+
// Handle errors...
35+
console.log(error)
36+
}
3237
};
3338

3439
// Try to retweet something as soon as we run the program...

0 commit comments

Comments
 (0)