Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

202
Views
Discord music bot in Javascript

After running this script there is no errors, but somehow when I try to use any of arguments like play nothing happens. I don't get any errors. Script just logs into Discord bot and nothing happens except that last line in which script gives feedback about proper login.

const { Client, Intents, Attachment} = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
const PREFIX = '!';
const ytdl = require("ytdl-core");

var servers = {};

client.on('message', message => {
    let args = message.content.substring(PREFIX.length).split(" ");

    switch (args[0]) {
        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", function(){
                    if(server.queue[0]){
                        play(connection, message);
                    }else {
                        connection.disconnect();
                    }
                });
            }

            if(!args[1]){
                message.channel.send("give a link");
                return;
            }

            if(!message.member.voiceChannel){
                message.channel.send("you must be on voice chat to play music");
                return;
            }

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

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

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

            if(!message.guild.voiceConnection) message.member.voiceChannel.join().then(function(connection){
                play(connection, message);
            })

        break;

        case "ping":
            message.channel.send("pong");
            console.log("pong");
            break;
    }
});

client.login(token);

client.on('ready', () => {
    console.log(`Logged in as ${client.user.tag}!`);
  });
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!