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
EDIT:
I just used a array filter now
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: