const Discord = require("discord.js")
const fetch = require("node-fetch")
const Database = require("@replit/database")
const db = new Database()
const client = new Discord.Client()
const sadWords = ["sad", "depressed", "unhappy", "angry"]
const starterEncouragements = [
"Dann guck dir paar memes an",
"Du kannst hamster zu jeder zeit nschreiben",
"Wenn du willst guck dir paar youtube videos an"
]
db.get("encouragements").then(encouragement => {
if (!encouragements || encouragements.length < 1) {
db.set("encouragements", starterEncouragements)
}
})
function uptadeEncouragements(encouragingMessage) {
db.get("encouragements").then(encouragements => {
encouragements.push([encouragingMessage])
db.set("encouragements", encouragements)
})
}
function deleteEncouragements(index) {
db.get("encouragements").then(encouragements => {
if (encouragements.length > index) {
encouragements.splice(index, 1)
db.set("encouragements", encouragements)
}
})
}
function getQuote() {
return fetch("https://zenquotes.io/api/random")
.then(res => {
return res.json()
})
.then(data => {
return data[0]["q"] + " -" + data[0]["a"]
})
}
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}!`)
})
client.on("message", msg => {
if (msg.author.bot) return
if (msg.content === "$inspire") {
getQuote().then(quote => msg.channel.send(quote))
}
if (sadWords.some(word => msg.content.includes(word))) {
db.get("encouragements").then(encouragements => {
const encouragement = encouragements[Math.floor(Math.random() * encouragements.length)]
msg.reply(encouragement)
})
}
if (msg.content.startsWith("$new")) {
encouragingMessage = msg.content.split("$new ")[1]
uptadeEncouragements(encouragingMessage)
msg.channel.send("New encouraging message added.")
}
if (msg.content.startsWith("$del")) {
index = parseInt(msg.content.split("$del ")[1])
deleteEncouragements(index)
msg.channel.send("encouraging message deleted.")
}
})
client.login(process.env.TOKEN)
and than it comes this on the console
Promise { <pending> }
Hint: hit control+c anytime to enter REPL.
(node:199) UnhandledPromiseRejectionWarning: ReferenceError: encouragements is not defined
(node:199) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:199) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Logged in as testRexGames#3316!
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.
your arrow function has a parameter, you never use that,
later you use a variable with a different name (difference of one letter) that doesn’t exist