Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

165
Views
How do I check if a subreddit exists in discord.js

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.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!