Вы можете определить состояние для пользователя и решить, где go дальше, основываясь, например, на ответе пользователя (я предположил какой-то идентификатор на клиентском объекте):
const userStates = {};
const replies = {
"": [
{
messages: ["hello"],
answer: "Hi! You wanna help with the codes?",
next_state: "asked_to_help",
},
],
asked_to_help: [
{
messages: ["no"],
answer: "Okay :(",
next_state: "",
},
{
messages: ["yes"],
answer: "Yay, tell me more!",
next_state: "some_next_stage",
},
],
};
client.on("message", async (message) => {
userStates[client.id] = userStates[client.id] || "";
const text = message.content.toLowerCase();
const possibleReplies = replies[userStates[client.id]].filter((reply) =>
reply.messages.includes(text)
); // filter by matching messages
const reply = possibleReplies [Math.floor(Math.random() * possibleReplies .length)]; // get random answer from valid ones
if (reply) {
message.channel.send(reply.answer);
userStates[client.id] = reply.next_state;
} else {
message.channel.send("I dont understand :(");
}
});