So im making a Slack bot where you can submit a journal you wrote. the admin can then also see what has been submitted with another command. What i’m trying to do right now is, when a journal gets submitted late, the User has to add a reason for it.
This is what i’ve got already. It works for now but the Problem is, that the event listener of app.message does not get “deleted” after going through the code once. This means that if the User subits another journal late the message
This is the reason you submitted: ${message.text}
get shown twice (if you do it 100 times after each other, it will get shown 100 times). This isnt good because it always tries to upload it to my MySQL DB each time.
I tried fixing it myself a few times also with the documentation (which does not include anything like this) and ChatGPT. Anyone knows how to fix this?
//checking if it gets uploaded on time^^^
else {
console.log("Late upload");
say(`Provide your reason for submitting late in your next message: `);
app.message(async ({ message, say }) => {
const ReasonUserInput = message.text;
if (ReasonUserInput) {
console.log("ReasonUserInput: ", ReasonUserInput);
}
if (ReasonUserInput) {
UploadToDatabase(
weekNumber,
currentYear,
user_id,
userParameters[0],
currentTimestamp,
ReasonUserInput,
db,
say,
command.user_id
);
say(`This is the reason you submitted: ${message.text}`);
}
});
here also what slackbot exactly does
enter image description here
Jonas Wildi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.