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

156
Visualizações
I'm trying to make a Discord Bot, only some features of jQuery works; ajax doesn't

So, I'm trying to make a (my first) Discord Bot. One command I'm coding is that each time a command is run, it adds a random number (500-1000) to a database (https://keyvalue.immanuel.co//). I tested out the ajax command for jQuery on a small testing Replit, and it worked just fine. However, when I run THE EXACT SAME CODE on Visual Studio:

$.ajax({
    type: "GET",
    url: `https://keyvalue.immanuel.co/api/KeyVal/GetValue/${database_key}/balance`,
    success: function (response) {
        message.channel.send(`Success! ${response} points was added to the world sum!`
    }
});

It gives me an error:

ReferenceError: $ is not defined

I'm so frustrated, because the following code from jQuery DOES work on my module, only ajax doesn't!

console.log(`I can use jquery to do the easy concatenation thing ${database_key}`)

And one last thing to remember: I ran the exact same AJAX code on Replit and it worked.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Remember to reference your scripts/cdn to jquery before the utilization of jquery itself.

You can use googles by including:

<head>
   <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>

And as @Jon P said, in this case it is much much better to fetch the results using the fetch function instead of an ajax function. An example of such code is listed below.

fetch(`https://keyvalue.immanuel.co/api/KeyVal/GetValue/${database_key}/balance`)
.then(res => res.text())
.then(response => message.channel.send(`Success! ${response} points was added to the world sum!`)
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