【发布时间】:2020-09-15 21:05:40
【问题描述】:
所以我目前正在制作一个不和谐的机器人,我制作了一个 ~play 命令,它从文件夹(歌曲)中读取文件并将它们存储在一个数组中,然后它会选择一个随机文件并在语音通道中播放它。
现在我想制作一首 ~songs,让机器人在聊天中发送一个嵌入内容,其中包含 .setTitle("These are that I have:"),然后是 .addField({name: "songs:", value: "*all the songs in the array"})。
我想要一个字段值中的所有歌曲的原因是歌曲太多,我只能使用 25 个字段。我在值和字段外都尝试了forEach,但没有一个效果很好。
这是我的代码:
const discord = require("discord.js");
const fs = require("fs");
module.exports.run = async (bot, message, args) => {
const songFiles = fs
.readdirSync("./commands/Workout/")
.filter((file) => file.endsWith(".mp3"));
let songsEmbed = new discord.MessageEmbed()
.setColor("RANDOM")
.setTitle("These are that I have:");
//.addField('Songname:',commandFiles.forEach())//doesn't work
for (i = 0; i < commandFiles.length; i++) {
songsEmbed.addField({ name: "Song name:", value: `${commandFiles[i]},` });
} //That just create field for every song
message.reply(songsEmbed);
};
module.exports.help = {
name: "songs",
};
【问题讨论】:
标签: javascript node.js discord discord.js