Jump to content

My code doesn't work. Help!

My code does not work and I have no idea where the missing comma is. Please help! 

(Sorry for it being sloppy. Im just learning coding)

My Code is Below:

const Discord = require('discord.js');

const bot = new Discord.Client();

//Deleted const so no one can see it
const token = ''
;
const PREFIX = '!';

const ytdl = require("ytdl-core");

var version = '0.7';

var servers = {};

bot.on('ready',() =>{
    console.log('This bot is online!');
    bot.user.setActivity ('Minecraft')

})
bot.on('message', msg=>{

    let args = msg.content.substring(PREFIX.length).split(" ");

    switch(args[0]){
        case 'ping':
            msg.channel.sendMessage('pong!');

            break;
        case 'ip':
            msg.channel.sendMessage('The server Ip is Nuclearwars.serv.gs');

            break;
        case 'info':
            if(args[1] === 'version'){
                msg.channel.sendMessage('Version ' + version);
            }else{
                msg.channel.sendMessage('Invalid Args')
            }

            break;
        case 'commands':
            msg.channel.sendMessage('The following commands are: info version, ip, and ping. There will be more commands coming soon!');
            break;
            case 'help':
            msg.channel.sendMessage('The following commands are: info version, ip, and ping. There will be more commands coming soon!');
            break;
    
            case 'play':

            function play(connection, message){
                var server = servers[message.guild.id];

                server.dispatcher = connection.playStream(ytdl(server.queue[0], {filter: "audioonly"}));

                server.queue.shift();

                server.dispatcher.on("end", funtion(),
                    if(server.queue[0]){
                        play(connection, message);
                    }else{
                        connection.disconnect();
                    }
                };

                if(!args[1]){
                    MessageChannel.channel.send("you need to provide a link!")
                    return;
                }

                if(!Message.member.voiceChannel){
                    message.channel.send("You must be in a channel to play the bot!")
                }

                if(!servers[message.guild.id]) servers[message.guild.id] = {
                    queue: []
                }

                var server = servers[message.guild.id];

                server.queue.push(args[1]);

                if(!message.quild.voiceConnetion) message.member.voiceChannel.join().then(funchtion(connection),{
                    play(connection,message);
                })
                break;
        }

    });

bot.login(token);

Here are the pictures of it to.

image.png

image.png

image.png

image.png

Edited by deathmonkey2019
Made it easier to look at the code.
Link to comment
Share on other sites

Link to post
Share on other sites

I just did what you said but that does not fix the problem

 

Link to comment
Share on other sites

Link to post
Share on other sites

Moved to programming and removed the second copy.

 

You're missing a { at the end of line 59 (as well as what's been said before).

HTTP/2 203

Link to comment
Share on other sites

Link to post
Share on other sites

7 hours ago, deathmonkey2019 said:

It says

image.png.6d097da3b052c95d436e09dbb1efd17d.png

It isn't the full output. You can find the actual error msg at the top.

ಠ_ಠ

Link to comment
Share on other sites

Link to post
Share on other sites

It would also be much easier to help if you just posted the code in code tags rather than screen shots. 

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

2 hours ago, deathmonkey2019 said:

I put it in <> form.

Also here is the full error message.

image.png.6080c3dced47916027f553d9a1ef1de3.png

 

 

                server.dispatcher.on("end", funtion(),
                    if(server.queue[0]){
                        play(connection, message);
                    }else{
                        connection.disconnect();
                    }
                };
                server.dispatcher.on("end", funtion(){
                    if(server.queue[0]){
                        play(connection, message);
                    }else{
                        connection.disconnect();
                    }
                };

 

ಠ_ಠ

Link to comment
Share on other sites

Link to post
Share on other sites

This looks like another typo:

if(!message.quild.voiceConnetion) message.member.voiceChannel.join().then(funchtion(connection),{
    play(connection,message);
})

"voiceConnetion" -> "voiceConnection"

"funchtion" -> "function"

Remember to either quote or @mention others, so they are notified of your reply

Link to comment
Share on other sites

Link to post
Share on other sites

19 hours ago, deathmonkey2019 said:

@EigenvektorI fixed all of what you have said, but I am still getting the same errors

Your code doesn't work because you have numerous errors. As @shadow_ray has pointed out, the compiler currently reports an error because of this:

server.dispatcher.on("end", funtion(), // <--- WRONG, the method body needs to start with a "{"
    if(server.queue[0]){
        play(connection, message);
    } else {
        connection.disconnect();
    }
}; // <-- Where's the matching "{"?

This is wrong. You have an unmatched closing curly brace. There is no opening curly brace after "function()". Because of this the "if" is unexpected, because you're not actually inside a function. To fix it, you have to provide a proper function body, like this:

server.dispatcher.on("end", funtion() { // CORRECT, function has a body now
    if (server.queue[0]) {
        play(connection, message);
    } else {
        connection.disconnect();
    }
};

Function is not just some arbitrary argument, so you can't just write "…, function(), …". The argument you're passing to the "on" method is the whole function including its body, so "…, function() { … }"

 

I merely pointed out additional typos that are probably going to be reported by the compiler once you fixed the current issue.

 

I would recommend to learn a bit more about the language you're using and learn to interpret the compiler's error messages. When the compiler spits out an error, it means you have done something incorrectly and as a developer it's your job to figure out what and why.

Remember to either quote or @mention others, so they are notified of your reply

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×