How to only check for messages after a specific person sent a message ? Discord JS

Viewed 36

Hello I am trying to use a discord bot to wait for a message from an admin of my server and then check the following messages from users. My code waits for the admin message however it somehow caches it ?? At least it doesnt check the users messages. I made my bot write the message where it got triggered to make it more understandable:

const Discord = require("discord.js");
const bot = new Discord.Client();
const bot_config = require("./settings.json")
var token = bot_config.usertoken
var userid = bot_config.userid
var channel = "940800688219369483"; //

bot.on("ready", () => {
    console.log(`SUCCESSFULLY LOGGED IN AS ${bot.user.tag}!`);
});
let counter = 0
bot.on("message", (msg) => {


//Waiting for mesage from specific admin
if(msg.author == "1011983215650672781"){   

if(counter == 0){ // check if message has already been send 
    if (msg.channel.id != channel) return; // Checks valid Channel ID

    if (msg.author == userid && msg.author == "703629528454660106" && msg.authot == "255396012045238222" && msg.authot == "142772377047199744" && msg.authot == "235748962103951360") { //CHECK IF NEXT MESSAGE IS NOT AN ADMIN
        console.log("ADMIN MESSGAE");
    }    
    else{
        let answer = msg.content
        bot.channels.cache.get(channel).send(answer)
        counter ++
        console.log("SUCCESSFULLY SENT MESSAGE")
        }          
} 
else{
    console.log("ALREADY SENT MESSAGE - CLOSE BOT")
} 
}
})  
bot.login(usertoken)

The problem is, the bot still writes the first admin message in the channel and not the onw from the first user

1 Answers

You might kick yourself for this, but you have used msg.authot instead of msg.author.id.

You may want to check out the docs, they come in handy when you need to know how to access properties.

Related