据我所知,数组中有一个零?因此,每次出现零作为“获胜者”时,就没有用户名可以调用,它会告诉聊天未定义已获胜?我该如何做到总是有一个获胜者?
const entries = {};
client.on('message', (channel, user, message, self) => {
if(self) return;
const entriesArr = Object.values(entries);
const randomNum = Math.floor(Math.random() * entriesArr.length);
const winner = entriesArr [randomNum];
if(message.toLowerCase() === '!join') {
entries[user.username] = user.username;
}
});
这是应显示获胜者的输出消息。 哪个有效,但永远不需要显示未定义的赢家。
setTimeout(() => {
client.action(TwitchHost, `"Looks like ${winner} walks out with the valuables! What happened to the others..?"`);
}, 2500);
问题出在你的身上 const randomNum = Math.floor(Math.random() *entriesArr.length)
SB const randomNum = Math.floor(Math.random() *entriesArr.length +1)