const 调度程序 = connection.playFile('C:/Users/Discord/Desktop/${myArray[Math.floor(Math.random() * 10)]}');
我需要connection.playFile
函数中的字符串能够从数组中获取值,以便我可以传入文件名。
最佳答案
使用反引号 ( template literal ) 代替单引号 '
。
然后您将能够访问 ${...}
中的变量
const dispatcher = connection.playFile(`C:/Users/Discord/Desktop/${myArray[Math.floor(Math.random() * 10)]})`
关于javascript - 在路径 Javascript 中使用变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59795335/