Reputation: 19
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
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}`);
}
Upvotes: 0
Views: 1197
Reputation: 11
You need to insert the "async" keyboard in your function, so: module.exports = async (msg) => {
Upvotes: 1
Reputation: 5174
The error says it all, the function in which you use await
needs to be asynchronous (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}`);
}
Upvotes: 1