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

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

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 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