Javascript 如果是Discord上的文字游戏大厅,如何让用户加入创建的大厅

Javascript 如果是Discord上的文字游戏大厅,如何让用户加入创建的大厅,javascript,node.js,discord,discord.js,Javascript,Node.js,Discord,Discord.js,我目前正在制作一个discord机器人,用户可以用它玩文字游戏 正如预期的那样,机器人会对命令做出反应。其中一个命令是“播放”。在这种情况下,我创建了一个名为createLobb()的函数和一个名为playersInLobby的数组 我的目标是让用户加入这个游说团。如果他们(他们的名字)能被推到阵型中就好了 这是我的。注意:如果两个玩家写“玩”,他们将被放在不同的大厅里。那不是我的目标。我的目标是让任何人都能创建一个大厅,其他人也加入进来。我想用if-else语句来检查用户是否在大厅,这可能是一

我目前正在制作一个discord机器人,用户可以用它玩文字游戏

正如预期的那样,机器人会对命令做出反应。其中一个命令是“播放”。在这种情况下,我创建了一个名为createLobb()的函数和一个名为playersInLobby的数组

我的目标是让用户加入这个游说团。如果他们(他们的名字)能被推到阵型中就好了

这是我的。注意:如果两个玩家写“玩”,他们将被放在不同的大厅里。那不是我的目标。我的目标是让任何人都能创建一个大厅,其他人也加入进来。我想用if-else语句来检查用户是否在大厅,这可能是一种可行的方法,但我想知道您将如何解决这个问题

代码段:

case "play":
                const maxplayers = 10;
                const minplayers = 4;
                globalThis.playersInLobby = [];

                function createLobby() { 
                    playersInLobby.push(user)
                    for (i = 0; i < playersInLobby.length; i++) {
                        bot.sendMessage({
                            to: channelID,
                            message: playersInLobby[i]
                        });
                    }
                    if (playersInLobby.length != minplayers) {
                        bot.sendMessage({
                            to: channelID,
                            message: playersInLobby.length + " out of (min: 4/max: 10) players in the lobby!"
                        });
                        bot.sendMessage({
                        to: channelID,
                        message: "Ready to play? We are still waiting for players"
                        });
                    }
                    else if (playersInLobby.length == minplayers) {
                        bot.sendMessage({
                            to: channelID,
                            message: "You may now start the game. However: the more players, the better the game!"
                        });
                    }
                    else if (playersInLobby.length == maxplayers) {
                        bot.sendMessage({
                            to: channelID,
                            message: "The lobby is full. The game has started!"
                        });
                    }
                    else {
                        bot.sendMessage({
                            to: channelID,
                            message: "ERROR! Something went wrong!!!"
                        });
                    }
                    //---------------------------------
                    lobbyexists = true;
                    console.log("Lobbyexists: " + lobbyexists);
                }
                createLobby();
案例“播放”:
常量maxplayers=10;
const minplayers=4;
globalThis.playersInLobby=[];
函数createLobble(){
playersInLobby.push(用户)
对于(i=0;i
感谢您的每一句评论!提前谢谢你