我如何让我的机器人发送一张随机的图片/模因。我使用的是discord.js,这就是我所能得到的。
if (msg.content === '-meme');
var randommeme = ({files:["https://cdn.discordapp.com/attachments/757397429107556422/757524795452686426/GBoat_Watermark.png"]} , {files:["https://cdn.discordapp.com/attachments/815040456244985947/816225078969892864/A_good_fluffy_goat.png"]});
var fact = Math.floor(Math.random() * randommeme.length);
msg.channel.send('goat meme', randommeme[fact]);
});这应该会发送一张随机的图片,但当我运行该命令时,它只显示“山羊表情包”。我以前试过这个代码,它起作用了。
client.on('message', msg => {
if (msg.content === '+meme') {
msg.channel.send("This is a good fluffy goat", {files: ["https://cdn.discordapp.com/attachments/757397429107556422/816234172737126430/A_good_fluffy_goat.png","https://cdn.discordapp.com/attachments/757397429107556422/757524795452686426/GBoat_Watermark.png"]});
}
});我真的不知道我做错了什么?
发布于 2021-03-06 15:42:20
首先创建一个链接数组,然后使用random函数从该数组中获取一个随机链接。
const meme = ['link_1','link_2','link_3','link_4'];
const index = Math.floor(Math.random() * meme.length);
message.channel.send('Goat meme',{files:[meme[index]]});其中link_1、link_2等是附件的URL。
发布于 2021-03-07 04:57:47
第二行有个拼写错误,正确的代码应该是:
var randommeme = ({files:["https://cdn.discordapp.com/attachments/757397429107556422/757524795452686426/GBoat_Watermark.png", "https://cdn.discordapp.com/attachments/815040456244985947/816225078969892864/A_good_fluffy_goat.png"]});https://stackoverflow.com/questions/66503193
复制相似问题