[英]Embed message gif not working | discord.js
The bot sends a embed message, but only the text and not the gif.机器人发送嵌入消息,但只发送文本而不发送 gif。 I have the gif in a separate.json file so there will be different gifs when someone uses the command.
我在单独的.json 文件中有 gif,因此当有人使用该命令时会有不同的 gif。 But for some reason it doesn't work.
但由于某种原因,它不起作用。 Maybe it's because of the.json file?
也许是因为.json 文件? 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: .json文件的代码:
{
"patgif": "https://i.pinimg.com/originals/15/d0/1e/15d01e231310bb6dabb3af0ae40fc209.gif"
}
(I know, its only one gif yet.) (我知道,它只有一个 gif。)
The error i get in the console when both files are in one folder: PICTURE: https://i.stack.imgur.com/8rzXP.png |当两个文件都在一个文件夹中时,我在控制台中遇到的错误:图片: 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这是消息的图片:图片: https://i.stack.imgur.com/nKGG3.png
Help would be appreciated, thank you: :)帮助将不胜感激,谢谢::)
There are a couple errors.有几个错误。 First, you need to fix the path, it's
require('../PATSGIFS.json')
.首先,您需要修复路径,它是
require('../PATSGIFS.json')
。
Another error is that the JSON file contains an object, not an array.另一个错误是 JSON 文件包含 object,而不是数组。 From your code, it seems you want to pick a random gif from an array, so it should be something like this instead:
从您的代码中,您似乎想从数组中选择一个随机 gif,所以它应该是这样的:
[
"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:您应该按原样发送嵌入,而不是在带有
embed
密钥的 object 内:
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);
},
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.