1

I'm trying to make a bot with a gif function. And i need for that the giphy api. I followed the steps from the giphy api docs but i everytime get a error message. jQuery is installed.

client.on('message', message => {
    if (message.content.startsWith('.gif')) {
        var url = $.get('https://api.giphy.com/v1/gifs/search?q=ryan+gosling&api_key=RnbFYGojZ3LOiMsnmMgrDElDLAqrXMJM&limit=5')
        url.done(function(data) { console.log("success got data", data); });

        const embed = new MessageEmbed()
        embed.setTitle('HIER EIN GIF, SHEESH');
        embed.setColor(0xB40404);
        embed.setDescription(url);
        message.channel.send(embed);
    }
});

ERROR:

ReferenceError: $ is not defined
    at Client.<anonymous> (C:\Users\Morit\WebstormProjects\discordbot\main.js:20:19)
    at Client.emit (events.js:375:28)
    at MessageCreateAction.handle (C:\Users\Morit\WebstormProjects\discordbot\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
    at Object.module.exports [as MESSAGE_CREATE] (C:\Users\Morit\WebstormProjects\discordbot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (C:\Users\Morit\WebstormProjects\discordbot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
    at WebSocketShard.onPacket (C:\Users\Morit\WebstormProjects\discordbot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
    at WebSocketShard.onMessage (C:\Users\Morit\WebstormProjects\discordbot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
    at WebSocket.onMessage (C:\Users\Morit\WebstormProjects\discordbot\node_modules\ws\lib\event-target.js:132:16)
    at WebSocket.emit (events.js:375:28)
    at Receiver.receiverOnMessage (C:\Users\Morit\WebstormProjects\discordbot\node_modules\ws\lib\websocket.js:970:20)
MrMythical
  • 8,908
  • 2
  • 17
  • 45
Moritz L.
  • 9
  • 3
  • 3
    *"jQuery is installed"* - The error indicates otherwise, and it's usually right about these things. Can you provide a more complete example? Perhaps you're loading jQuery after this code executes? Perhaps you have something that removes the `$` variable to avoid jQuery conflicting with anything else? Isn't this code running in Node.js, why would you use jQuery **at all** for that? I wouldn't expect jQuery to work in Node.js in any way. Have you seen [Can I use jQuery with Node.js?](https://stackoverflow.com/q/1801160/328193) – David Jul 20 '21 at 21:28
  • 5
    Have you imported jQuery? Anyway, why would you use jQuery on the backend? Why don't you use `node-fetch`, `axios`, or something else to fetch data from the API? – Zsolt Meszaros Jul 20 '21 at 21:28

0 Answers0