1
votes

The bot sends a embed message, but only the text and not the gif. I have the gif in a separate .json file so there will be different gifs when someone uses the command. But for some reason it doesn't work. Maybe it's because of the .json file? I really don't know, please help me. My code:

const Discord = require('discord.js');
const prefix = require('../config.json');
const patGif = require('../PATSGIFS.json');

module.exports = {
  name: "pat",
  description: "Pat someone UwU",
  aliases:["pat"],


execute: async (client, message, args) => {
    const gif = patGif[Math.floor(Math.random() * patGif.length)];

    if (!message.mentions.users.first())
    return message.reply("***please mention someone.***");
    
    const embed = new Discord.MessageEmbed()
    .setColor("#FF8DC4 ")
    .setTitle(`*Aww how cute, ${message.author.username} gave ${message.mentions.users.first().username} a pat!*`) 
    .setImage(gif);(String[patGif[gif]])
    message.channel.send({embed})
}} 

The code of the .json file:

{
    "patgif": "https://i.pinimg.com/originals/15/d0/1e/15d01e231310bb6dabb3af0ae40fc209.gif"
}

(I know, its only one gif yet.)

The error i get in the console when both files are in one folder: PICTURE: https://i.stack.imgur.com/8rzXP.png | I can't copy it from the console, so here's a picture.

Here's a picture of the message: PICTURE: https://i.stack.imgur.com/nKGG3.png

Help would be appreciated, thank you! :)

1
Is the filename uppercase PATSGIFS.json? - Zsolt Meszaros
Yes it is. Why? - ツtanni
Because it says it can't find ../PATSGIFS.json. Could you also take a screenshot of your folders showing this JSON file? - Zsolt Meszaros
Sure. I only have these two files in my command folder right now. i.postimg.cc/k5TSS44k/patsgifs.png - ツtanni
It works now - Thank you. But there's still no gif. - ツtanni

1 Answers

0
votes

There are a couple errors. First, you need to fix the path, it's require('../PATSGIFS.json').

Another error is that the JSON file contains an object, not an array. From your code, it seems you want to pick a random gif from an array, so it should be something like this instead:

[
  "https://i.pinimg.com/originals/15/d0/1e/15d01e231310bb6dabb3af0ae40fc209.gif",
  "https://i.pinimg.com/originals/15/d0/1e/15d01e231310bb6dabb3af0ae40fc209.gif",
  "https://i.pinimg.com/originals/15/d0/1e/15d01e231310bb6dabb3af0ae40fc209.gif",
]

And you should send the embed as-is, not inside an object with an embed key:

message.channel.send(embed)

The full code:

const Discord = require('discord.js');
const prefix = require('../config.json');
const patGif = require('./PATSGIFS.json');

module.exports = {
  name: 'pat',
  description: 'Pat someone UwU',
  aliases: ['pat'],
  execute: async (client, message, args) => {
    const gif = patGif[Math.floor(Math.random() * patGif.length)];

    if (!message.mentions.users.first())
      return message.reply('***please mention someone.***');

    const embed = new Discord.MessageEmbed()
      .setColor('#FF8DC4')
      .setTitle(
        `*Aww how cute, ${message.author.username} gave ${
          message.mentions.users.first().username
        } a pat!*`,
      )
      .setImage(gif);

    message.channel.send(embed);
  },
}; 

enter image description here