How can i pull out r/copypasta content and use it as a string?

I programmed a Discord-bot which replies to recieved dms with "bruh dming me has literally no point". A friend gave me this amazing idea to pull out the answers from r/copypasta. But i dont know how to do that so i asked. The important part of the code:

client.on('message', message => { if (message.channel.type === "dm" && message.author.id !== client.user.id) { console.log("-----DM-----") console.log(message.content) console.log(message.author.tag) console.log("-----DM-----") message.author.send("bruh dming me has literally no point"); client.channels.cache.get('726919268142415973').send({ embed: { color: 0x00baba, author: { name: "I recieved the following DM:", icon_url: message.author.avatarURL }, title: message.author.tag, description: message.content, timestamp: new Date(), footer: { icon_url: client.user.avatarURL, text: "Staff" } } }); }
});

2 Answers

What you want is to use the reddit API to pull content from a certain subreddit. Reddit's api is open to public, you COULD register your app and use their official API

Or you could use their open endpoints ! No need for credentials that way

  1. Call GET . (Change sort=new by any of those: rising, hot, top, new ...). This will return you a JSON of results, just parse the JSON and get the copypastas needed!

  2. At the end of the JSON, there are 2 elements : "after": "t3_hi5yy6", "before": nullThose are your "next page" and "previous page" ids. To get the next page, you simply need to call : GET

example using axios:

var url = ""
var response = await axios.get(url);
var after = response.data.data.after;
var copypastas = response.data.data.children.map(x => x.data.selftext);
//copypastas now contains an array of strings being copypatas;
//Change url with url+="&after="+after and repeat the process in a loop
0

I now came up with this:

 if (message.channel.type !== 'text') { if (message.author.id == client.user.id) return; fetch("") .then((out) => { console.log(out) message.reply(`${out.data.data.children[0].data.selftext}`); }); return;
}

(I know i could also do if (message.author.bot) return; instead of if (message.author.id == client.user.id) return; but maybe some bots redirect their DMS in a channel lol)

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like