【发布时间】:2022-02-14 00:38:37
【问题描述】:
我已经尝试了很多我见过的东西,但似乎没有一个对我有用。我使用的是当你执行命令时它会激活命令文件夹中的文件,而大多数其他脚本不使用它。
【问题讨论】:
-
呃,抱歉这里的图片描述,我是新手;)
-
使用
.json存储大量图片
标签: javascript node.js discord discord.js
我已经尝试了很多我见过的东西,但似乎没有一个对我有用。我使用的是当你执行命令时它会激活命令文件夹中的文件,而大多数其他脚本不使用它。
【问题讨论】:
.json存储大量图片
标签: javascript node.js discord discord.js
没有看到任何代码,很难为您指明正确的方向。这将有助于更多地定义您遇到的问题(实际错误和/或功能)以及查看您正在使用的代码。解决方案还取决于图像的来源。
假设您的图像位于本地文件夹中,这是一个基本示例:
if (message.content === '!random') {
// get a random index between 0 and length
const idx = (len) => Math.floor(Math.random() * (len));
// get all the files in the directory
const files = fs.readdirSync('/images/');
// get file from directory
const myImage = files[idx(files.length)];
// send image to channel
message.channel.send({ files: [`/images/${myImage}`] });
}
假设图片来自https://picsum.photos/,这是一个基本示例:
if (message.content === '!random') {
const seed = Math.floor(Math.random() * 1000);
const h = Math.floor(Math.random() * 400) + 100;
const w = Math.floor(Math.random() * 400) + 100;
// create embed with random image
const embed = new MessageEmbed().setImage(`https://picsum.photos/seed/${seed}/${h}/${w}`);
// send embed
message.channel.send({ embeds: [embed] });
// delete command
message.delete();
}
【讨论】: