I am having problems with my discord music bot, its getting really weird. I have one old discord bot that is able to play music but the command handling isn’t that good. So I made a new bot with better command handling but now something really weird is happening. I am using the exact same code but I am getting errors in await and async functions. I really need some help this thing is driving me crazy.
OLD Discord bot (The one that does play music, all commands are in server.js)
NEW Discord bot (The one I am having problems with, play command is in folder commands)
I suggest regenerating your token, and using .env instead for your token as anyone that has clicked into your project above can now access your bot as the token was in a public file.
Could you please invite me to your project in a private message (Click on my user image => click message) and I will be happy to help you with it! I will also try help you with your error at the same time!
Ok so I fixed the original problem you were having, and the issue with using process.env, that you mentioned!
The original issue I fixed by adding this:
(async () => {
// The rest of the commands code here
})();
const ytdl = require("ytdl-core");
const Discord = require("discord.js");
var async = require('asyncawait/async');
var servers = {};
module.exports = {
name: 'play',
description: 'Plays a song',
execute(message, args) {
(async () => {
message.delete(20)
if (!message.member.voiceChannel) return message.channel.send('❌ Please join a voice channel.');
if (message.guild.me.voiceChannel) return message.channel.send('❌ Error, the bot is already connected to another music channel or a song is playing.');
if (!args[0]) return message.channel.send('❌ Error, please enter a **URL** following the command.');
let validate = await ytdl.validateURL(args[0]);
if (!validate) return message.channel.send('❌ Error, please input a __valid__ url following the command.');
let info = await ytdl.getInfo(args[0]);
let connection = await message.member.voiceChannel.join();
let dispatcher = await connection.playStream(ytdl(args[0], {
filter: 'audio',
quality: 'highestaudio',
volume: '0.5'
}));
let playembed = new Discord.RichEmbed()
.setColor("#7cfc00")
.setTitle("🎶 Now playing:")
.setDescription(`${info.title}`)
message.channel.send(playembed);
})();
}
}
That is the command after I added that piece of code.
The env issue you were having was happening because you were doing: