[英]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.我试过
if(images = "[link]") embed.setFooter("Hello!")
但是这个页脚在每张图片上,而不仅仅是在一张图片上。 Now three "=" because of the comment instead of 1:)现在三个“=”因为评论而不是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
希望能帮助到你
You need to compare the randomly selected image, not the images
array.您需要比较随机选择的图像,而不是
images
数组。 You could also create a randomImage
variable for this image:您还可以为此图像创建一个
randomImage
变量:
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!')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.