So I was making a command to browse reddit for images, using the npm package 'trev'
const trev = require("trev");
module.exports = {
name: 'reddit',
description: "Gets an image from reddit",
async execute(message, args, client, Discord) {
const sub = args[0]
const subr = await trev.getCustomSubreddit(sub)
it works perfectly fine if I enter a subreddit which exists, but if i enter an inexistent subreddit for the first argument, then the code crashes and gives me and error, so I want to know if there is a way to check if the subreddit actually exists.
I would advice you to use a other package.
trev is broken for getting a inexistent subreddit
The index.js has a var typo :
async getCustomSubreddit(subreddit) {
...
while (r[0] === undefined && tentatives < 5) {
let r = await getsubreddit(subreddit);
tentatives++;
}
...
}
It should be :
async getCustomSubreddit(subreddit) {
...
while (r[0] === undefined && tentatives < 5) {
let r = await this.getSubreddit(subreddit);
tentatives++;
}
...
}
You could try and modify the package to make this work, in the \node_modules\trev\index.js file
By doing that, the function would actually work, and requesting a inexistent subreddit would return undefined and log out :
[-] Broken subreddit: /r/subreddityouwant