• If you need help or want to discuss things, you now can also join us on our Discord Server!

EN New command : list [SOLVED]

guillaumearnx

New Member
Hello, I want to create a list command for the bot for list all tracks in a message.

JavaScript:
command.createCommand('list1')
        .addArgument(command.createArgument('rest').setName('searchstring'))
        .checkPermission(requirePrivileges(PLAYBACK, ENQUEUE))
        .exec((client, args, reply, ev) => {
            // print syntax if no searchstring given
            const tracks = media.getTracks()
            reply(tracks);
            successReaction(ev, reply);
        });

        command.createCommand('list2')
        .addArgument(command.createArgument('rest').setName('searchstring'))
        .checkPermission(requirePrivileges(PLAYBACK, ENQUEUE))
        .exec((client, args, reply, ev) => {
            // print syntax if no searchstring given
            var tracks = media.getTracks()
            reply(tracks.length);
            successReaction(ev, reply);
        });

        command.createCommand('list3')
        .addArgument(command.createArgument('rest').setName('searchstring'))
        .checkPermission(requirePrivileges(PLAYBACK, ENQUEUE))
        .exec((client, args, reply, ev) => {
            // print syntax if no searchstring given
            media.getTracks()
            track.forEach(function(item){
                reply(item);
            });
            successReaction(ev, reply);
        });

        command.createCommand('list4')
        .addArgument(command.createArgument('rest').setName('searchstring'))
        .checkPermission(requirePrivileges(PLAYBACK, ENQUEUE))
        .exec((client, args, reply, ev) => {
            // print syntax if no searchstring given
            media.getTracks()
            const response = track[track.length];
            reply(response);
            successReaction(ev, reply);
        });

Here are 4 different commands but none succeeds, I have an error each time
 

Caudex

Insider
Insider
I have an error each time
Yeah, but seems like you wouldn't share it with us. 🙃

Have you installed and activated the command library? Have you imported any command object through
JavaScript:
const command = require("command");
?


If you really want to get help, you should provide all necessary information...
 
Last edited:
I can't say exactly what is not working in your scripts, specially without the output error on the logs. It seems you are not treating the return of media.getQueue() properly. According to the docs, this returns an Array of Tracks, so you need to convert this to a string somehow before this is useful in a reply.

Here is my implementation of a similar command, to show all the tracks in the queue. You can easily adapt this one to your needs, replacing the media.getQueue with whatever function you need and the format class as well. Also if your library is too big, be careful. The output may be too long and not really useful.

JavaScript:
// Showing only the relevant snips of code
// The formatTrack is the one in the sinusbot-commands.js script.
    function formatResultTrackList(track, index) {
        return `${index+1}. ${formatTrack(track)}`
    }
// ...
            createCommand('queuelist')
            .alias('ql')
            .help('Shows the current queue')
            .manual('Shows all songs in the queue to play')
            .checkPermission(requirePrivileges(PLAYBACK))
            .exec((client, args, reply, ev) => {
                let tracks = media.getQueue();
                let response = tracks.map(formatResultTrackList).join("\n");
                if (response == "") {
                    response = "No songs in the queue.";
                }
                reply(response);
                successReaction(ev, reply);
            });
 

TwentyFour

BinusSot Junkie
V.I.P.
Contributor
Insider
Also if your library is too big, be careful. The output may be too long and not really useful.
Or just not even printed in a message due to the char limits of teamspeak... but that can be cut in the script ... anyways is there any reason, you would print all tracks in a text, than just look it up in the webinterface?
 

guillaumearnx

New Member
here is my error
Code:
2020-05-12T22:15:33+02:00 [ command:41:14] ReferenceError: track is not defined at command.createCommand.addArgument.checkPermission.exec (sinusbot-commands:367:13)
All librairies are includes because my code is in the sinusbot-commands.js file
 

Multivitamin

Well-Known Member
Tier III
is awesome!
V.I.P.
is uber awesome!
Contributor
Insider
Its all in the error message^^

JavaScript:
command.createCommand('list3')
  .addArgument(command.createArgument('rest').setName('searchstring'))
  .checkPermission(requirePrivileges(PLAYBACK, ENQUEUE))
  .exec((client, args, reply, ev) => {
    // print syntax if no searchstring given
    media.getTracks()
    //probably here -> track is undefiend
    track.forEach(function(item){
      reply(item);
    });
    successReaction(ev, reply);
  });
 

Multivitamin

Well-Known Member
Tier III
is awesome!
V.I.P.
is uber awesome!
Contributor
Insider
Yes it returns an array of tracks but you dont save it into a variable
 

Caudex

Insider
Insider
I don't know if it is really necessary but I'm always using the "var" or "let" keyword when defining a new variable:
JavaScript:
var tracks = media.getTracks();
 

guillaumearnx

New Member
I've tried this 3 commands :
JavaScript:
command.createCommand('list1')
        .addArgument(command.createArgument('rest').setName('searchstring'))
        .checkPermission(requirePrivileges(PLAYBACK, ENQUEUE))
        .exec((client, args, reply, ev) => {
            // print syntax if no searchstring given
            var tracks = media.getTracks()
            reply(tracks);
            successReaction(ev, reply);
        });

        command.createCommand('list2')
        .addArgument(command.createArgument('rest').setName('searchstring'))
        .checkPermission(requirePrivileges(PLAYBACK, ENQUEUE))
        .exec((client, args, reply, ev) => {
            // print syntax if no searchstring given
            var tracks = media.getTracks()
            const response = tracks.map(formatTrack).join("\n")
            reply(response);
            successReaction(ev, reply);
        });

        command.createCommand('list3')
        .addArgument(command.createArgument('rest').setName('searchstring'))
        .checkPermission(requirePrivileges(PLAYBACK, ENQUEUE))
        .exec((client, args, reply, ev) => {
            // print syntax if no searchstring given
            var tracks = media.getTracks()
            let response = tracks.map(formatTrack).join("\n");
            reply(response);
            successReaction(ev, reply);
        });
But none responded

2020-05-12T23:17:33+02:00 [ command:41:14] guillaumearnx (689576146765086830/629786143906594828) used $list3
2020-05-12T23:17:31+02:00 [ command:41:14] guillaumearnx (689576146765086830/629786143906594828) used $list2
2020-05-12T23:17:28+02:00 [ command:41:14] guillaumearnx (689576146765086830/629786143906594828) used $list1
 

Multivitamin

Well-Known Member
Tier III
is awesome!
V.I.P.
is uber awesome!
Contributor
Insider
the function reply generally expects a string as response not an object or string
 
OP, did you actually tried using my version and replace the relevant parts? It seems you lack some programming knowledge to fill in the blanks of the parts you are not doing correctly. It seems easier to just copy my queuelist command, replace command name, alias, description and replace the media.getQueue() line for media.getTracks() and the result will match exactly what you need.
 
Last edited:

guillaumearnx

New Member
I tested directly with the getQueue command, it works (I have the music in the queue)
But when I adapt it for the list command, I do not receive any response and in the logs I have:
2020-05-14T15:37:26+02:00 [ command:41:14] guillaumearnx (689576146765086830/629786143906594828) used $list

JavaScript:
function formatResultTrackList(track, index) {
        return `${index+1}. ${formatTrack(track)}`
    }
            createCommand('list')
            //I've tried with "command.createCommand('list')" too
            .alias('l')
            .help('Shows all tracks in the directory')
            .manual('Shows all songs present in the Musicos directory')
            .checkPermission(requirePrivileges(PLAYBACK))
            .exec((client, args, reply, ev) => {
                let tracks = media.getQueue();
                let response = tracks.map(formatResultTrackList).join("\n");
                if (response == "") {
                    response = "Il n'y a aucun son dans le répertoire";
                }
                reply(response);
                successReaction(ev, reply);
            });
Here is a sample command so you can see the syntax that works :
JavaScript:
 command.createCommand('whoami')
        .help('Show user identities')
        .manual('Shows user identities matching your ID/groups.')
        .exec((client, args, reply, ev) => {
            let users = getUsersByClient(client);
            if (users && users.length != 0) {
                reply(`You match the following users: ${users.map(user => user.name()).join(", ")}.`);
            } else {
                reply("You don't match any users.");
            }
            successReaction(ev, reply);
        });
 
So maybe the answer is just too long for the TS/discord message limit, so nothing is printed. I had this issue in other command I implemented.

You can try splitting the answer in several replies, in case this is the issue.
 

TwentyFour

BinusSot Junkie
V.I.P.
Contributor
Insider
Yes there is a limit in direct messages as well. But why don't you try to get your output to the log first, and if you succeeded, then think about what to do with the output?

That's like caring for the dishes on the table, while you haven't started cooking. :D
 

Similar threads

Top