Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

166
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda