await 仅在异步函数 discord.js 中有效

Slameko552

我正在为我的服务器制作音乐播放机器人,但我认为我做错了什么。我正在做那个视频,但我收到await is only valid in async function错误

module.exports = (msg) => {   
const ytdl = require('ytdl-core');

if (!msg.member.voiceChannel) return msg.channel.send('Please Connect to a voice channel');

if (msg.guild.me.voiceChannel) return msg.channel.send('Im in another channel');

if(!args[1]) return msg.channel.send('no URL no music');

let validate = await ytdl.validateURL(args[1]);

if(!validate) return msg.channel.send('Please input a valid url following the command');

let info = await ytdl.getInfo(args[1]);

let connection = await msg.member.voiceChannel.join();

let dispatcher = await connection.play(ytdl(args[1], {filet: 'audioonly'}));

msg.channel.send(`Now playing : ${info.title}`);
}
合成器

错误说明了一切,您使用的函数await需要是异步的 ( async)

module.exports = async (msg) => {   
const ytdl = require('ytdl-core');

if (!msg.member.voiceChannel) return msg.channel.send('Please Connect to a voice channel');

if (msg.guild.me.voiceChannel) return msg.channel.send('Im in another channel');

if(!args[1]) return msg.channel.send('no URL no music');

let validate = await ytdl.validateURL(args[1]);

if(!validate) return msg.channel.send('Please input a valid url following the command');

let info = await ytdl.getInfo(args[1]);

let connection = await msg.member.voiceChannel.join();

let dispatcher = await connection.play(ytdl(args[1], {filet: 'audioonly'}));

msg.channel.send(`Now playing : ${info.title}`);
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

“await 仅在异步函数中有效” discord.js

await 仅在异步函数 Discord bot 反应角色中有效

获取 SyntaxError: await 仅在异步函数和模块的顶层主体中有效,同时通过 discord.js 指南工作

Await仅在使用Node.js的异步函数中有效

Sails.js SyntaxError:await 仅在异步函数中有效

即使等待位于 Node.js 中的异步函数中,如何修复“await 仅在异步函数中有效”?

Javascript 函数 await 仅在异步函数中有效

for循环中的“ await仅在异步函数中有效”

For 循环 - SyntaxError: await 仅在异步函数中有效

SyntaxError: await 仅在异步函数和模块的顶层主体中有效。不和谐,js

discord.js机器人等待仅在异步功能中有效

给出 await 的异步函数仅在异步函数中有效

“await 仅在异步函数中有效”,而它是一个异步函数

await 总是抛出 SyntaxError: await 仅在 sequelize 的异步函数中有效

ASYNC / AWAIT SyntaxError:await 仅在异步函数和模块的顶级主体中有效

Google Cloud / Firebase 函数:await 仅在异步函数中有效

SyntaxError:await 仅在带有 Apify Metamorph 的异步函数中有效

SyntaxError:当使用Node JS连接到Mongo DB时,await仅在异步功能中有效

await 仅在异步函数和模块的顶层主体中有效 javascript express error

控制台错误:await 仅在异步函数和模块的顶层主体中有效

`SyntaxError:await 仅在异步函数中有效`,同时尝试在 node rest api 中注册用户

await仅在异步功能中有效-异步中的eval

未捕获的 SyntaxError:await 仅在 async 函数中的 async 函数中有效

SyntaxError:“await”仅在“async”函数中有效 - 需要帮助

SyntaxError:await 仅在 async 函数中有效,但 async 已包含在内

为什么我的 await 在我的功能中不起作用?“语法错误:等待仅在异步函数中有效”

Javascript:SyntaxError:等待仅在异步函数中有效

等待仅在异步函数中有效,同时我已经在函数中放置了“异步”

await仅在异步功能错误中对异步功能有效