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

EN Documented engine.getUserById wasn't found

Lauriichen

Member
Hello,
so I'm trying to make a script in js that allows the user to type (example prefix: !) !follow to get the bot into his/her channel.
But Sinusbot don't want to execute my event for that correctly.
Everytime I try to use that command it says "engine.getUserById is not a function" even though it is documented on the Scripting Engine documentation page (https://sinusbot.github.io/scripting-docs/)
Does someone has an idea for a work around?

Here the current script
JavaScript:
const ENQUEUE           = 1 << 13;
registerPlugin({
    name: 'follow command',
    version: '1.0',
    backends: ['discord'],
    engine: '>= 0.13.37',
    description: 'Implements the !follow and !goaway command',
    author: 'Lauriichan <[email protected]>',
    vars: [{
        name: 'defaultChannel',
        title: 'Name or ID of the default channel (needed for !goaway)',
        type: 'channel'
    }]
}, function (config) {
    const ENGINE = require('engine');
    const BACKEND = require('backend');
    const EVENT = require('event');

    EVENT.on('message', function (event) {
        var client = event.author();
        if (client.isSelf()) {
            return;
        }
        var id = client.id();
        var user = ENGINE.getUserById(id);

        if((user.privileges() & ENQUEUE) == 0) {
            return;
        }

        var text = event.content();
        if(!text.startsWith(ENGINE.getCommandPrefix())) {
            return;
        }
        text = text.replace(ENGINE.getCommandPrefix(), "");

        switch(text) {
            case "follow": {
                var channel = client.getAudioChannel();
                if(channel == null) {
                    return;
                }
                ENGINE.log('Trying to follow (' + client.name() + ') - moving to (' + channel.name() + ').');
                BACKEND.getBotClient().moveTo(channel);
            }
            case "goaway": {
                var channel = BACKEND.getChannelById(config.defaultChannel);
                ENGINE.log('Going back to my default channel (' + channel.name() + ').');
                BACKEND.getBotClient().moveTo(channel);
            }
        }

    });
});
EDIT:
I just used a array filter now
 
Last edited:

Tuetchen

Diesmon Dominator
is awesome!
Contributor
Insider
You want to use BACKEND.getClientByID()
The Engine user functions are for the Sinusbot webinterface user not the teamspeak clients

Still weird that engine.getUserById is not a function - it should be available - even though its doing something different to what you need for your usecase
 

Lauriichen

Member
You want to use BACKEND.getClientByID()
The Engine user functions are for the Sinusbot webinterface user not the teamspeak clients

Still weird that engine.getUserById is not a function - it should be available - even though its doing something different to what you need for your usecase
No I wanted the Sinusbot webinterface user that was absolutely correct but thanks for your answer :)
 

Tuetchen

Diesmon Dominator
is awesome!
Contributor
Insider
Well but the Client ID in Teamspeak is a different ID than the User ID in the webinterface

var id = client.id();
var user = ENGINE.getUserById(id);
So this doesnt make sense
 

Lauriichen

Member
So even though it makes no sense, that doesn't fix the bug that the function isn't available and I saw that after I looped through the array.
And like I said in my Edit I solved at with a simple Array filter now.
Here the code if you want to see it:

JavaScript:
        var users = ENGINE.getUsers().filter(user => user.tsUid() === client.uid());
        if (users.length == 0) {
            return;
        }

        if ((users[0].privileges() & ENQUEUE) == 0) {
            return;
        }
And also, I know it doesn't really matter but that script was (as you can see on the top) for discord not teamspeak c.c
 

Similar threads

Top