"await is only valid in async functions" 而它是一个异步函数
"await is only valid in async functions" while it's an async function
出于某种原因我收到此错误:
SyntaxError: await is only valid in async functions and the top level bodies of modules
我不知道它有什么问题。这显然是一个异步函数。
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);
}
你的内部函数不是异步的。
出于某种原因我收到此错误:
SyntaxError: await is only valid in async functions and the top level bodies of modules
我不知道它有什么问题。这显然是一个异步函数。
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);
}
你的内部函数不是异步的。