Discord. Js / Node. Js - Await Is Only Valid in Async Function
Why Is This Happening? ?? Try { Var Connection = Await voiceChannel. Join(); } Catch (Error) { Console. Error(`I Could Not Join to the Voice Channel...
Why is this happening???
try {
var connection = await voiceChannel.join();
} catch (error) {
console.error(`I could not join to the voice channel: ${error}`);
return message.channel.send(`I could not join the voice channel: ${error}`);
}
1 Answer
The answer is in the error message. You can't use the await statement inside a function that isn't declared as async.
Incorrect:
function doSomething() {
var result = await doSomethingElse()
}
Correct:
async function doSomethingAsync() {
var result = await doSomethingElse()
}
More information on async functions here at MDN.