Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

172
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda