我有这段代码可以说“正在监视(我的机器人所在的服务器数量)服务器!”
const activities_list = [
"with the &help command.",
"with the developers console",
"with some code",
"with JavaScript",
client.guilds.size + " servers!"
];
client.on('ready', () => {
setInterval(() => {
const index = Math.floor(Math.random() * (activities_list.length - 1) + 1);
client.user.setActivity(activities_list[index]);
}, 5000);
});
但是当我不和谐地看到它时,它就给了我
“ 0台服务器!”
我该如何解决?
答案 0 :(得分:0)
我认为问题在于您在客户端准备就绪之前就声明了字符串(当您键入带有变量的字符串时,该字符串将与该值一起保存)。尝试在setInterval
参数中声明它:
client.on("ready", () => {
setInterval(() => {
let activities = ["your_strings", `${client.guilds.size} servers!`],
index = Math.floor(Math.random() * (activities_list.length - 1) + 1);
client.user.setActivity(activities[index])
}, 5000);
});