-2

Can someone help me out? I'm actually stuck. This the the source code for a bot I made to send GIFs when requesed by a user in a server. The bot is online and connecting to the Discord API. Discord bot getting online image The bot should be activated when typed !gif , in keyword the user can type any categorie or emotion they want and the bot would get the gif. There are no errors shown yet but the bot is still not replying. No reply image Bot online image I am also getting valid reply when used the giphy api url.

const Discord = require('discord.js');
require('dotenv').config();
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] });
client.on('ready', () => {   
console.log(`Logged in as ${client.user.tag}!`); 
});  
client.on("messageCreate", async (message) => {
    const tokens = message.content.split(" ");
  
    if (tokens[0] == "!gif") {
      const keywords = tokens.slice(1, tokens.length).join(" ");
      const url = `http://api.giphy.com/v1/gifs/search?q=tag&api_key=token&limit=5`;
      const response = await fetch(url);
      const result = await response.json();
      const index = Math.floor(Math.random() * result.results.length);
      message.channel.send(result.results[index].url);
    }
  });
client.login(process.env.DISCORD_BOT_TOKEN);


I tried many online fixes none worked I also tried changing version of Discord.js, node-fetch as well as dotenv but none worked.
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Dec 18 '22 at 22:40

1 Answers1

0

Discord.js v14

const { Client, GatewayIntentBits, Events } = require('discord.js')
require('dotenv').config()

const client = new Client({
    intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.MessageContent,
        GatewayIntentBits.GuildMembers,
        GatewayIntentBits.GuildMessages,
    ],
})
client.on(Events.MessageCreate, async (message) => {
    if (message.author.id === client.user.id) return
    const token = message.content.split(' ')
    if (token[0] === '!gif')
        message.channel.send({
            content: `<@${message.author.id}>`,
            files: ['https://media.tenor.com/fTTVgygGDh8AAAAM/kitty-cat-sandwich.gif'],
        })
})

client.on(Events.ShardReady, () => {
    console.log(`Logged in as ${client.user.tag}!`)
})

client.login(process.env.TOKEN)
  • Hi again I changed my code according to your info but there was still no response changing version solved the issue. Thanks for the help. There is one more thing the bot os sending files instead of gifs what should I do about that? – Its me Ashhad Dec 14 '22 at 10:33
  • The link of the file must end with .gif – Currente Calamo Dec 14 '22 at 11:38
  • oh I think you dont understand or Ithink its me but I want to use API giphy as mentioned in the code the result is something like this. https://imgur.com/a/ruLWpd2 https://imgur.com/a/97KKhoe The bot is giving response thanks to you. Its my first time making a bot so a little nervous! – Its me Ashhad Dec 14 '22 at 11:50