Answer the question
In order to leave comments, you need to log in
If the user wrote a message and it contains a mention of the user who is in the array in the database. How to do?
Let's say the user wrote a message: "<@mention>, test test". If the user specified a person who is in the array in the database, then the bot, for example, writes: "Accepted."
how it looks like in db:
i tried to do like this:
bot.on("message", message => {
if(message.channel.name === "reports") {
Guild.findOne({guildID: message.guild.id}, async(err, guild) => {
if(err) console.log(err);
if(!guild) {
let NewGuild = new Guild({guildID: message.guild.id})
NewGuild.save()
}
if(guild.ModersOnline.includes(message.content)) {
message.channel.send("Принял.")
console.log(message.content)
console.log(message.content.includes(guild.ModersOnline))
}
})
}
})
Answer the question
In order to leave comments, you need to log in
var input = "Ruby" // ввод пользователя
var array = ["JavaScript", "Objective-C", "Ruby", "Python", "Haskell", "Clojure", "PHP", "C++"] // массив
var check = () => {
if (array.includes(input)) { // если в массиве находится элемент "Ruby" (ввод пользователя), вернуть истину
return true
} else {
return false // если нет - ложь
}
}
console.log(check()) // true, в массиве есть элемент "Ruby"
input = input.replace("Ruby", "Swift") // заменили ввод пользователя на Swift
console.log(check()) // false, в массиве нету такого элемента
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question