Javascript wait仅在异步函数discord.js中有效
我正在为我的服务器制作音乐播放机器人,但我想我做错了什么。 我是这样做的,但我得到了Javascript wait仅在异步函数discord.js中有效,javascript,node.js,discord.js,Javascript,Node.js,Discord.js,我正在为我的服务器制作音乐播放机器人,但我想我做错了什么。 我是这样做的,但我得到了await仅在异步函数中有效 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)
await仅在异步函数中有效
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)=>{
常量ytdl=require('ytdl-core');
如果(!msg.member.voiceChannel)返回msg.channel.send('请连接到语音频道');
如果(msg.guild.me.voiceChannel)返回msg.channel.send('Im在另一个频道');
如果(!args[1])返回msg.channel.send('no URL no music');
让validate=wait ytdl.validateURL(args[1]);
如果(!validate)返回msg.channel.send('请在命令后面输入有效的url');
let info=wait ytdl.getInfo(args[1]);
let connection=wait msg.member.voiceChannel.join();
let dispatcher=wait connection.play(ytdl(args[1],{filet:'audioonly'}));
msg.channel.send(`Now playing:${info.title}`);
}
错误说明了一切,您使用的wait
函数需要是异步的(async
)
module.exports=async(msg)=>{
常量ytdl=require('ytdl-core');
如果(!msg.member.voiceChannel)返回msg.channel.send('请连接到语音频道');
如果(msg.guild.me.voiceChannel)返回msg.channel.send('Im在另一个频道');
如果(!args[1])返回msg.channel.send('no URL no music');
让validate=wait ytdl.validateURL(args[1]);
如果(!validate)返回msg.channel.send('请在命令后面输入有效的url');
let info=wait ytdl.getInfo(args[1]);
let connection=wait msg.member.voiceChannel.join();
let dispatcher=wait connection.play(ytdl(args[1],{filet:'audioonly'}));
msg.channel.send(`Now playing:${info.title}`);
}
您需要在函数中插入“异步”键盘,因此:module.exports=async(msg)=>{您需要在函数中插入“异步”键盘,因此:module.exports=async(msg)=>{谢谢伙计!非常感谢!非常感谢伙计!非常感谢!不客气,欢迎你这么做。如果一个答案解决了你的问题,你应该接受它,这让其他人知道问题已经得到了回答,也让寻找答案的人知道什么有效。不客气,欢迎这么做。如果一个答案解决了你的问题,你应该接受我t、 这让其他人知道问题已经得到了回答,也让寻找答案的人知道什么有效