0

I'm getting this error for some reason:

SyntaxError: await is only valid in async functions and the top level bodies of modules

I've no idea what's wrong with it. It's obviously an async function.

const muteCheckTimer = async (client) => {
setInterval(() => { 
    db.each(query, [], (err, row) => {
        if(err) {
            console.log(err);
            return;
        }
        if(row) {
            let currentTimestamp = Date.now();
            if(currentTimestamp > row.mutedTimestamp) {
                let user = await client.users.fetch(row.userID);
                if(!user.member) { console.log('Not a user') }

                let MutedRole = user.member.guild.roles.cache.find((r) => r.name === "Muted");
                if(!MutedRole) { console.log("Muted role doesn't exists") }
                
                //await user.member.roles.remove(MutedRole);
                
            } else {
                console.log('MUTED');
            }

        }

    });
}, 10000);

}

2
  • 2
    Neither () => { nor (err, row) => { are marked as async. Commented Sep 4, 2021 at 2:33
  • Doesn't look like muteCheckTimer needs to be async however. Commented Sep 4, 2021 at 2:35

1 Answer 1

2

Your inner function is not async.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.