Skip to content
Advertisement

Change footer regarding on image in discord.js

When the image of an embed is randomized, is there a way to change the footer regarding on the image that is used in a message? I have tried if(images = "[link]") embed.setFooter("Hello!") But then this footer is on every image, not just on one. Now three “=” because of the comment instead of 1 🙂

Complete code:

const { DiscordAPIError } = require("discord.js");
const Discord = require('discord.js');
const client = new Discord.Client();
const prefix = "=";

module.exports = {
    name: 'hug',
    description: "Hug a user!",
    execute(message, args, embedMsg) {
        try {
    const user2 = message.mentions.members.first();
    args[0] = `=hug ${user2}`;
    let images = ["https://media.giphy.com/media/3bqtLDeiDtwhq/giphy.gif" , "https://thumbs.gfycat.com/EthicalNecessaryAssassinbug-size_restricted.gif" ,"https://i.pinimg.com/originals/b6/2f/04/b62f047f8ed11b832cb6c0d8ec30687b.gif",
                    "https://media1.tenor.com/images/5c35f9a6052b30442d05a855fc76b5de/tenor.gif?itemid=6004346" ,"http://media.giphy.com/media/yziFo5qYAOgY8/giphy.gif" , "http://giphygifs.s3.amazonaws.com/media/143v0Z4767T15e/giphy.gif" ,
                    "https://media1.tenor.com/images/9917c221691759f3f464e8ce8522ac0e/tenor.gif?itemid=6502610" , "https://media1.tenor.com/images/969f0f462e4b7350da543f0231ba94cb/tenor.gif?itemid=14246498" , "https://gifimage.net/wp-content/uploads/2017/06/anime-hug-gif-12.gif" ,
                    "https://pa1.narvii.com/6103/57a8748b56d6f34b678a3998c92522883ae45749_hq.gif" , "https://media1.tenor.com/images/c7efda563983124a76d319813155bd8e/tenor.gif?itemid=15900664" , "https://33.media.tumblr.com/7f397e9ff5341d21212567b674a2fb13/tumblr_nkmb4cRVXo1sx3znro1_500.gif"]
    const result = Math.floor(Math.random() * images.length);
    const error = new Discord.MessageEmbed()
    .setColor("#993333")
    .setTitle("Hug")
    .setDescription(`Check if you mentioned a user other than you!`)
    .setFooter(message.author.username)
    .setTimestamp()
    ;

    if(!user2) return message.reply(error);
    if(user2.id === message.author.id) return message.reply(error);

    const embed = new Discord.MessageEmbed()
    .setColor("#993333")
    .setTitle("Hug")
    .setDescription(`<@${message.author.id}> hugs <@${user2.user.id}>! n n > ${args[1]}`)
    .setImage(images[result])
    .setTimestamp()
    ;
    if(!args[1]) embed.setDescription(`<@${message.author.id}> hugs <@${user2.user.id}>!`)
    if(images === "https://i.pinimg.com/originals/b6/2f/04/b62f047f8ed11b832cb6c0d8ec30687b.gif") embed.setFooter("Hello!")
    message.delete();
    message.channel.send(embed).then((embedMsg) => {
        const emojis = ['🙂', '🙁'];
        emojis.forEach((emoji) => embedMsg.react(emoji));
        
        const filter = (reaction, user) =>
        !user.bot && emojis.includes(reaction.emoji.name) && user.id === user2.user.id;

        const collector = embedMsg.createReactionCollector(filter, {max: 1});

        collector.on('collect', (reaction) => {
          const [yes, no] = emojis;
          if (reaction.emoji.name === yes) {
              embedMsg.edit(embed.setDescription(`<@${message.author.id}> hugged <@${user2.user.id}> and they gave them a hug back! n n > ${args[1]}`));
          }

          if (reaction.emoji.name === no) {
            embedMsg.edit(embed.setDescription(`<@${message.author.id}> hugged <@${user2.user.id}> but they pushed them away! n n > ${args[1]}`));
        }
        })

    })
} catch(e) {
    message.channel.send("❌ Sorry!   Something went wrong there. Please report the bug using =feedback.")
    console.log(e);
}
    }}

Full code is there now! Hope it helps

Advertisement

Answer

You need to compare the randomly selected image, not the images array. You could also create a randomImage variable for this image:

const images = [
 // ...
]

const embed = new Discord.MessageEmbed()
  .setColor('#993333')
  .setTitle('Hug')
  .setDescription(
    `<@${message.author.id}> hugs <@${user2.user.id}>! n n > ${args[1]}`,
  )
  .setImage(randomImage)
  .setTimestamp()

// randomly picked URL from the images above
const randomImage = images[Math.floor(Math.random() * images.length)]

// ...

if (randomImage === 'https://i.pinimg.com/originals/b6/2f/04/b62f047f8ed11b832cb6c0d8ec30687b.gif')
  embed.setFooter('Hello!')
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement