在路径 JavaScript 中使用变量



const dispatcher = connection.playFile('C:/Users/Discord/Desktop/${myArray[Math.floor(Math.random() * 10)]}');

我需要connection.playFile函数中的字符串能够从数组中获取值,以便我可以传入文件名。

使用反引号(模板文字(而不是单引号'.

然后,您将能够访问${...}中的变量

const dispatcher = connection.playFile(`C:/Users/Discord/Desktop/${myArray[Math.floor(Math.random() * 10)]})`

最新更新