Он действительно использует переменную для результата toLowerCase () и использует logi c с переключателем или ifs со значениями в нижнем регистре для правильного сравнения.
const safari = function(message) {
message.channel.send(embed).then(()=>{
message.channel.awaitMessages(filter, {
max: 1,
time: 30000,
errors: ['time']
}).then(collected=>{
let msg = collected.first().toLowerCase();
/* switch version */
switch (msg) {
case "look at reflection":
{
const embed2 = new discord.RichEmbed().setTitle("__**Chat to a tourist!**__").setColor("#49499c").setDescription("You begin to look at yourself, and slowly become infatuated with yourself!\n**__Wait 24 hours before guessing again!__**")
message.channel.send(embed2);
break;
}
case "pond dip":
{
const embed2 = new discord.RichEmbed().setTitle("__**Off road!**__").setColor("#49499c").setDescription("You begin to pond dip, you had such a blast!")
message.channel.send(embed2);
break;
}
case "chase a frog":
{
const embed2 = new discord.RichEmbed().setTitle("__**Trip over a rock!**__").setColor("#49499c").setDescription("Oh you're very clumbsy luckily its only a bruise!")
message.channel.send(embed2);
break;
}
default:
{
message.channel.send("Could not find this answer");
return safari(message);
}
}
/* if version */
if (msg == "look at reflection") {
const embed2 = new discord.RichEmbed().setTitle("__**Chat to a tourist!**__").setColor("#49499c").setDescription("You begin to look at yourself, and slowly become infatuated with yourself!\n**__Wait 24 hours before guessing again!__**")
message.channel.send(embed2);
} else if (msg == "pond dip") {
const embed2 = new discord.RichEmbed().setTitle("__**Off road!**__").setColor("#49499c").setDescription("You begin to pond dip, you had such a blast!")
message.channel.send(embed2);
} else if (msg == "chase a frog") {
const embed2 = new discord.RichEmbed().setTitle("__**Trip over a rock!**__").setColor("#49499c").setDescription("Oh you're very clumbsy luckily its only a bruise!")
message.channel.send(embed2);
} else {
message.channel.send("Could not find this answer");
return safari(message);
}
}
).catch(collected=>{
message.channel.send('Time up');
}
);
}
);
}
Возможно, вы можете обновить свой JS с ES6 и async / await вместо стиля Promises. Также ... если использовать сохраненные ответы, это может быть более гибким, попробуйте что-то вроде этого ...
class Message extends String {
channel = new Channel()
}
class Channel {
async awaitMessages(filter, options) {
let messages = new Collection();
messages.push(new Message("pond dip"))
return messages;
}
async send(msg) {
}
}
class Collection extends Array {
first() {
return this[0];
}
}
class Discord {
RichEmbed() {
return new Element()
}
}
class Element {
setTitle() {
return this;
}
setColor() {
return this;
}
setDescription() {
return this;
}
}
let discord = new Discord()
let answers =
{
"look at reflection": { title: "__**Chat to a tourist!**__", color: "#49499c", description: "You begin to look at yourself, and slowly become infatuated with yourself!\n**__Wait 24 hours before guessing again!__**" },
"pond dip": { title: "__**Off road!**__", color: "#49499c", description: "You begin to pond dip, you had such a blast!" },
"chase a frog": { title: "__**Trip over a rock!**__", color: "#49499c", description: "Oh you're very clumbsy luckily its only a bruise!" },
}
async function safari(message) {
try {
let embed = "embed";
let filter = undefined;
await message.channel.send(embed);
let collected = await message.channel.awaitMessages(filter, {
max: 1,
time: 30000,
errors: ['time']
});
let msg = collected.first().toLowerCase();
let answer = answers[msg];
if (answer) {
const embed2 = discord.RichEmbed().setTitle(answer.title).setColor(answer.color).setDescription(answer.description)
return message.channel.send(embed2);
} else {
return message.channel.send("Could not find this answer");
}
} catch (error) {
console.error(error);
return message.channel.send('Time up');
}
}
safari(new Message("test"))