image - 如何让我的不和谐机器人发送随机模因/图片
问题描述
如何让我的机器人发送不和谐的随机图片/模因。我正在使用 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]);
});
这应该会发送一张随机图片,但是当我运行该命令时,它只会显示“goat meme”。我之前尝试过这段代码并且它有效。
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"]});
}
});
我真的不知道我在这里做错了什么?
解决方案
首先创建一个链接数组,然后使用 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。
推荐阅读
- html - 如何从上到下为 div 设置动画?像一颗流星
- flutter - 一旦失焦,文本字段就会刷新
- node.js - npm publish 尝试发布到 github 包注册表时忽略 dist 目录中的文件
- javascript - 获取完全呈现的日历页面的实际高度(FullCalendar)
- google-apps-script - 锁定工作表然后导出 URL
- r - R - 如何根据包含日期序列的向量的值将列添加到数据框/data.table
- r - 最长的 Collatz 序列 1:n
- sql-server - 在 Excel Microsoft Data Query 中嵌入用户名和密码,以便其他用户可以刷新数据
- java - 找不到答案,Jersey 404 错误,当转到网页 rest/*,git 代码 https://gitlab.com/Kaidstor/job-access
- python - OpenCV 只接受我在 PyCharm 中的路径字符串