[英]await is only valid in async function discord.js
I was making music play bot for my server but i think i did something wrong.我正在为我的服务器制作音乐播放机器人,但我认为我做错了什么。 I was doing like that video but i'm getting await is only valid in async function
error我正在做那个视频,但我得到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}`);
}
The error says it all, the function in which you use await
needs to be asynchronous ( async
)错误说明了一切,您使用await
的 function 需要是异步的( 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}`);
}
You need to insert the "async" keyboard in your function, so: module.exports = async (msg) => {您需要在 function 中插入“异步”键盘,因此:module.exports = async (msg) => {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.