This scripting-documentation lists all available modules and their methods implemented in the current SinusBot Scripting Engine.
Check out our guide in the SinusBot Documentation for explanations on how to get started.
The code used to generate this documentation can be found here on GitHub. Contributions are welcome!
There is also a documentation available for the command-library that was introduced with sinusbot-1.0.0-alpha.
This is the first and only top-level function that should be called in your script, everything else will be done in the function that is passed to it.
(Manifest)
The manifest determines which features are available to the script and
contains metadata and variables that will be shown in the web interface.
(mainFunction)
If the script is activated this function is called when the scripts are loaded.
The function receives three parameters, the first one (
_
) is deprecated and should not be used anymore.
registerPlugin({
name: 'Demo Script',
version: '1.0',
description: 'This example actually does nothing',
author: 'Author <author[at]example.com>',
vars: []
}, function(_, config, meta) {
// your code goes here
});
Type: object
(string)
: Short name of your script
(string)
: Your name and your email address in the form of:
your name <your-email@example.com>
(string)
: A longer description - tell the user what exactly your script does
(string)
: Start with something like 1.0 and increase it with every release
(boolean?)
: Set to true, if you want the script to be run on every instance, without the option to disable it.
(Array<string>?)
: Per default scripts will only be available on TS3 instances.
If your script supports Discord (or in the future maybe other backends) as well, you have to specify this explicitly by setting this variable to an array containing all backends:
backends: ["ts3", "discord"]
(boolean?)
: If your script required own web content, you can set enableWeb to true and put files into the ./scripts/scriptname/html directory.
After restart, the script title will be clickable and lead to an index.html inside that html-directory you just created.
From there you have access to the localStorage variables containing the login and may communicate with the bot api from your own pages.
(string?)
: Sets the required engine version (bot version). This uses
Semantic Versioning
. Example:
engine: ">= 0.9.16"
(boolean?)
: Hides the script from the settings page. Should be used together with autorun.
Hidden scripts can not have variables (vars), since they'd never be shown and thus not configurable.
(Array<string>?)
: An array of protected modules (i.e. 'http' or 'db') that the script requires.
(Array<string>?)
: This parameter is only used for the speech recognition feature and may contain one or more strings that are to be detected for the given script.
You can find more details on how to use it here:
Speech Recognition
Type: Function
(object?)
This parameter is deprecated and should not be used anymore.
(object)
Configuration of the plugin that the user set from within the web interface
(given you have added anything to the vars field of your script manifest).
(Manifest)
Manifest as specified in registerPlugin.
Modules which can be imported via require(<module name>)
const engine = require('engine');
engine.log('Hello from a script!');
sets the log level of the instance
level | what gets logged
------|-----------------
0 | no log messages
1 | errors only
2 | errors and warnings
3 | errors, warnings, information
4 | ...
10 | most verbose
11 | most verbose + external backends
(number)
Log level to set
boolean
:
Logs to stdout / instance log.
Note:
{}
because the values are returned by functions and not stored as properties.<nil>
.
To get the actual value in the log you need to convert it to a string first.(...any)
const engine = require('engine');
engine.log('Hello from a script!');
const a = 42;
const b = 1337;
// can be logged like this:
engine.log('a is ' + a + ', and b is ' + b + '.');
// or a bit nicer with an es6 templates string:
engine.log(`a is ${a}, and b is ${b}.`);
// see https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/template_strings
// examples of common mistakes:
// converting an object to a string like this will *NOT* print what you want:
const cat = {says: 'meow'};
engine.log(`cat: ${cat}`); // => will print: "cat: [object Object]"
engine.log(cat); // => will (probably) print: "{"says":"meow"}"
// to print it's values you can also convert it to JSON:
engine.log(`cat: ${JSON.stringify(cat)}`); // => will print: "cat: {"says":"meow"}"
// but this will not work with classes like Client or Channel!
engine.log(JSON.stringify(aClientObj)) // => will print: "{}"
engine.log(aClientObj) // => will print: "Client{ ID: <something>, Name: <irgendwr> }"
// but an array of clients/channels/... will NOT be printed as you would expect:
engine.log([aClientObj, aClientObj]) // => will print: "[{},{}]"
Exports an object, so other Scripts are able to use functions or values of the Script
Note: Since SinusBot v1.0.0 you can now use the standard module.exports = {...};
instead, as shown below.
(object)
object which should get exported
// scriptname: exportscript.js
var publicvariable = 'I get exportet!';
module.exports = {
// returns the value of 'publicvariable'
get: () => {
return publicvariable;
},
// modifies the value of 'publicvariable'
set: (value) => {
publicvariable = value;
}
};
// ----------------------------------------------
// old way of exporting:
// var engine = require('engine');
// engine.export({
// // returns the value of 'publicvariable'
// get: function () {
// return publicvariable;
// },
// // modifies the value of 'publicvariable'
// set: function (value) {
// publicvariable = value;
// }
// })
// ----------------------------------------------
// import in another script:
var event = require('event');
var engine = require('engine');
event.on('load', function() {
// must always be loaded AFTER the 'load' event
var script = require('exportscript.js');
engine.log(script.get()); // logs 'I get exportet!'
script.set('New Value');
engine.log(script.get()); // logs 'New Value'
});
Disables the register command
Enables the register command
var store = require('store');
store.set('foo', 'bar');
Gets a variable that has been stored previously by set() the values stored are only available for the current script, but shared between instances of it
(string)
any
:
Stored value - or undefined, if not found
var store = require('store');
var foo = store.get('foo');
Creates a new channel
(ChannelParams)
Channel
:
Channel which was created
Returns a servergroup by its ID
(string)
ServerGroup ID
ServerGroup
:
Returns a channelgroup by its ID
(string)
ChannelGroup ID
ChannelGroup
:
Returns an array of all known server groups
Array<ServerGroup>
:
Returns an array of all known channel groups
Array<ChannelGroup>
:
Searches for tracks matching the search term, returns 20 entries at most
(string)
Array<Track>
:
var event = require('event');
var media = require('media');
event.on('chat', function(ev) {
var params = ev.text.split(' ');
if (params.length == 1) {
ev.client.chat('Please enter a searchterm after .play - like .play november rain');
return;
}
if (params[0] == '.play') {
params.shift();
var results = media.search(params.join(' '));
if (results.length > 0) {
results[0].play();
ev.client.chat('Playing - just for you: ' + results[0].artist() + ' - ' + results[0].title());
} else {
ev.client.chat('Sorry, I could not find anything that matched your search.');
}
}
});
Plays the next track of the queue; resumes queue if stopped.
Alias for playQueueNext()
. Plays the next track of the queue; resumes queue if stopped.
Clears the idle track.
Clears the startup track.
Applies a ffmpeg filter to the audio output.
Warning: This method is curretly not safe to use and leads to crashes!
(string)
ffmpeg compatible filter string
boolean
:
success
Apply color if the backend supports it
string
:
Formatted string
// Sends a red-colored message to the server chat (requires permission to do so)
var backend = require('backend');
var format = require('format');
backend.chat('This is SinusBot writing in ' + format.color('red', '#aa0000'));
Apply italic formatting to text
(string)
string
:
Formatted string
// Sends a formattes message to the server chat (requires permission to do so)
var backend = require('backend');
var format = require('format');
backend.chat('Part of this message is ' + format.italic('italic'));
Apply bold formatting to text
(string)
string
:
Formatted string
// Sends a formattes message to the server chat (requires permission to do so)
var backend = require('backend');
var format = require('format');
backend.chat('Part of this message is ' + format.bold('bold'));
Apply underlined formatting to text
(string)
string
:
Formatted string
// Sends a formatted message to the server chat (requires permission to do so)
var backend = require('backend');
var format = require('format');
backend.chat('Part of this message is ' + format.underline('underlined'));
Creates an empty BytesWriter
BytesWriter
:
Returns a BytesWriter for a given string
(string)
String
BytesWriter
:
Returns a BytesWriter for a given hex-string
(string)
Hex-string
BytesWriter
:
Returns a BytesWriter for a given base64-string
(string)
Base64-string
BytesWriter
:
var event = require('event');
var engine = require('engine');
event.on('chat', function(ev) {
engine.log('Got message "'+ev.text +'" from '+ ev.client.name());
})
Gets fired whenever api:{sinusbot address}/api/v1/bot/i/{instanceID}/event/{eventName}
with the POST
method and the correct headers.
This can only be called by users that are logged in and authenticated via the Authorization
header. For a public api event see public:<your event name>
.
(ApiEvent)
API event
// ** SinusBot Script **
event.on('api:logMyFoo', ev => {
engine.log(ev.data().foo);
});
// this is the short form of: function(ev) {return {something: '...'}}
event.on('api:respondWithSomething', ev => ({
something: 'Hello browser, how are you doing?'
}));
// ** JavaScript on the web-page **
// This example uses jQuery but you can very easily rewrite it to work without it by using "fetch".
// See https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
// This assumes you're logged in and the webpage is included with the script.
// HTTP API methods to Login and get a list of the Instances are documented here: https://www.sinusbot.com/api/
// Information on how to include a webpage can be found here: https://sinusbot.github.io/docs/scripts/#enableweb-bool
//TODO: Rewrite this to use fetch.
function sendDataToScript(instanceID) {
$.ajax({
url: '/api/v1/bot/i/' + instanceID + '/event/logMyFoo',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'bearer ' + window.localStorage.token
},
data: JSON.stringify({"foo": "bar"})
});
}
function requestDataFromScript(instanceID) {
$.ajax({
url: '/api/v1/bot/i/' + instanceID + '/event/respondWithSomething',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'bearer ' + window.localStorage.token
},
data: '{}'
}).done(function (data) {
console.log("Response:");
console.log(data);
});
}
Gets fired whenever public:{sinusbot address}/api/v1/b/i/{instanceID}/event/{eventName}
with the POST
method.
This is similar to api:<your event name>
with the only difference being
that no authentication is required.
(ApiEvent)
API event
event.on('public:foobar', ev => {
engine.log('Received foobar event from api!');
// JSON data is in: ev.data()
});
// This event can be triggered by sending a http `POST` request to `{sinusbot address}/api/v1/b/{botId}/i/{instanceID}/event/foobar`.
// Data can be passed by sening JSON in the request body.
This event gets triggered whenever a chat message has been received. This also counts for messages from the bot itself, so make sure to check.
(Message)
Message
var event = require('event');
var engine = require('engine');
event.on('chat', function(ev) {
engine.log('Got message "'+ev.text +'" from '+ ev.client.name());
});
Note: This event is only for discord messages. For both TS3 and Discord messages use the chat event.
This event gets triggered whenever a discord message has been received.
(DiscordMessage)
Message
var event = require('event');
event.on('message', msg => {
// like message
msg.createReaction('👍');
});
Gets fired whenever the bot is poked
(Message)
Message
var event = require('event');
var engine = require('engine');
event.on('poke', function(msg) {
engine.log('Got poke message "' + msg.text + '" from ' + msg.client.name());
});
Gets fired whenever a client starts typing in a chat with the bot
(Client)
Client that started typing
Gets fired whenever a track changes its information (like radio stations)
(Track)
Gets fired whenever a track was successfully downloaded via ytdl
event.on("ytdl.success", ev => {
engine.log(`Successfully downloaded a YouTube Video: ${ev.url}, jobId: ${ev.jobId}, trackId: ${ev.trackId}`)
})
Gets fired whenever a download via ytdl fails
(string)
Error Message
event.on("ytdl.error", (ev, message) => {
engine.log(`Error while downloading a YouTube Video: ${ev.url}, jobId: ${ev.jobId}, message: ${message}`)
})
Gets fired whenever a connection with the server has been established
Gets fired whenever the client is unable to connect to a server
(string)
Gets fired whenever the bots connection to the server is closed
Gets fired whenever a client moves, joins or disconnects
(MoveInfo)
Gets fired whenever a client becomes visible to the bot
(MoveInfo)
Gets fired whenever a client becomes invisible to the bot
(MoveInfo)
Gets fired whenever a client gets kicked from the server
(MoveInfo)
Gets fired whenever a client gets kicked from a channel
(MoveInfo)
Gets fired whenever a clients IP address changes or has initially been fetched
(Client)
Gets fired whenever a client sets himself as away
(Client)
Gets fired whenever a client removes himself as away
(Client)
Gets fired whenever a client starts recording
(Client)
Gets fired whenever a client stops recording
(Client)
Gets fired whenever a client mutes his microphone
(Client)
Gets fired whenever a client unmutes his microphone
(Client)
Gets fired whenever a client mutes his sound
(Client)
Gets fired whenever a client unmutes his sound
(Client)
Gets fired whenever a client is banned from a TS server
Gets fired whenever a client got added to a server group
(ClientServerGroupEvent)
Gets fired whenever a client got removed from a server group
(ClientServerGroupEvent)
gets fired when a client connection info gets updated
(Client)
the client which got updated
This event gets triggered whenever the bot recognizes a voice command that the script registered, assuming: 1) SpeechRecognition was installed 2) SpeechRecognition is enabled in the config.ini 3) The voice command was registered by the script in registerPlugin 4) AudioReturnChannel is set to 2
Check out the documentation for reqirements and instructions on how to install it.
var event = require('event');
var engine = require('engine');
var audio = require('audio');
audio.setAudioReturnChannel(2)
event.on('speech', function(ev) {
engine.log('Got speech command "' + ev.text + '" from ' + ev.client.name());
});
Gets fired whenever the number of users that are currently talking in the channel changes
(number)
Number of users that are currently talking in the channel
Gets fired whenever the script is going to be unloaded or reloaded; use this to clean up or save stuff
Gets fired when all scripts have been loaded
This event gets triggered whenever a discord event got received. Every event will be emitted in uppercase and the spaces will be replaced by underscores. All available discord events can be found in the discord documentation
(object)
Discord event data
var event = require('event');
var engine = require('engine');
event.on('discord:GUILD_CREATE', function (ev) {
engine.log('GUILD_CREATE' + JSON.stringify(ev));
});
This event is fired when calling backend.extended().requestExtendedServerInfo() when the backend is TS3.
(TeamSpeakExtendedServerInfo)
This module is protected. This means that you need to add 'http'
to requiredModules
in your script's Manifest in registerPlugin in order to use it - like shown here:
registerPlugin({
name: 'Demo http basic Script',
version: '1.0.0',
description: 'This example script sends a http request.',
author: 'Author <author@example.com>',
//...
// define the protected modules that you require:
requiredModules: ['http'],
//...
vars: []
}, (_, config, meta) => {
const engine = require('engine');
// and then you can require and use the module in here:
const http = require('http');
// send request
http.simpleRequest({
'method': 'GET',
'url': 'https://example.com',
'timeout': 6000,
}, function (error, response) {
if (error) {
engine.log("Error: " + error);
return;
}
if (response.statusCode != 200) {
engine.log("HTTP Error: " + response.status);
return;
}
// success!
engine.log("Response: " + response.data.toString());
});
});
Examples can be found under simpleRequest.
Creates an http request
(object)
http configuration object
Name | Description |
---|---|
config.method string?
|
Request Method to use (eg GET, POST, PUT, ...) |
config.url string
|
The URL endpoint which should be called |
config.timeout number?
|
timeout in milliseconds |
config.body string?
|
request body |
config.headers object?
|
request header |
(simpleRequestCallback)
Callback function with error and response
registerPlugin({
name: 'Demo http basic Script',
version: '1.0.0',
description: 'This example script sends a http request.',
author: 'Author <author@example.com>',
requiredModules: ['http'], // <-- don't forget this!
vars: []
}, (_, config, meta) => {
// import modules
const engine = require('engine');
const http = require('http');
// send request
http.simpleRequest({
'method': 'GET',
'url': 'https://example.com',
'timeout': 6000,
}, function (error, response) {
if (error) {
engine.log("Error: " + error);
return;
}
if (response.statusCode != 200) {
engine.log("HTTP Error: " + response.status);
return;
}
// success!
engine.log("Response: " + response.data.toString());
});
});
registerPlugin({
name: 'Demo http basic Script',
version: '1.0.0',
description: 'This example script sends a http request and sends+receives json data.',
author: 'Author <author@example.com>',
requiredModules: ['http'], // <-- don't forget this!
vars: []
}, (_, config, meta) => {
// import modules
const engine = require('engine');
const http = require('http');
// define data that should be sent
var sendData = JSON.stringify({ foo: 'bar' });
// send request
http.simpleRequest({
'method': 'POST',
'url': 'https://example.com',
'timeout': 6000,
'body': sendData,
'headers': {
'Content-Type': 'application/json',
'Content-Length': sendData.length
}
}, function (error, response) {
if (error) {
engine.log("Error: " + error);
return;
}
if (response.statusCode != 200) {
engine.log("HTTP Error: " + response.status);
return;
}
// parse JSON response
var res;
try {
res = JSON.parse(response.data.toString());
} catch (err) {
engine.log(err.message);
}
// check if parsing was successfull
if (res === undefined) {
engine.log("Invalid JSON.");
return;
}
// success!
engine.log(res);
});
This module is protected. This means that you need to add 'net'
to requiredModules
in your script's Manifest in registerPlugin in order to use it.
The net module allows you to connect to any TCP/UDP port or ws (websocket) and send raw data. If you just need to send a http request then you should definitely use the http module instead.
const engine = require('engine');
const net = require('net');
// connect to a tcp port
const conn = net.connect({
host: '127.0.0.1',
port: 80
}, err => {
// log connection errors if any
if (err) {
engine.log(err);
}
});
// start listening for data
conn.on('data', data => {
engine.log('received data');
engine.log(data.toString());
})
// write data if connection is available
if (conn) {
// write data
conn.write("GET / HTTP/1.1\r\nHost: localhost\r\n\r\n");
} else {
engine.log('connection unavailable');
}
(NetConnectParams)
Connection parameters
(netConnectCallback)
Callback gets called on success/error.
NetClient?
:
Client connection, or null if failed to setup a connection
(e.g. wrong parameters; null does not mean that the connection failed, instead that it is handled in the callback)
This module is protected. This means that you need to add 'ws'
to requiredModules
in your script's Manifest in registerPlugin in order to use it.
The ws module allows you to start a websocket server. If you want to connect to a websocket server instead then take look at the net module.
Please consider using http api events for simple communications instead, as they are simpler and also allow you to require authentication; See api:<your event name>
and public:<your event name>
for more.
// ### SinusBot script: ###
const engine = require('engine');
const event = require('event');
const ws = require('ws');
// listen for connections
event.on('ws.connect', id => {
engine.log('new websocket connection; id ' + id);
// broadcast data to all connected clients
ws.broadcast(1, { blubb: 'blubb' });
});
// listen for disconnections
event.on('ws.disconnect', id => {
engine.log('websocket connection disconnected; id ' + id);
});
// listen for data
event.on('ws.data', (id, type, data) => {
engine.log('ws.data: id ' + id + '; data: ' + data.toString());
// respond with data
ws.write(id, type, data.toString());
});
// ### Client Side (served html files via the enableWeb script option): ###
var proto = (window.location.protocol == 'https:') ? 'wss' : 'ws';
var conn = new WebSocket(proto + "://" + document.location.host + "/api/v1/b/" + botId + "/i/" + instanceId + "/ws");
conn.onclose = function (evt) {
console.log('close', evt);
alert('Closed.');
};
conn.send(JSON.stringify({ type: 'ping' }));
conn.onmessage = function (evt) {
var data = JSON.parse(evt.data);
};
This module is protected. This means that you need to add 'db'
to requiredModules
in your script's Manifest in registerPlugin in order to use it.
Use additional parameters to exec / query whenever you use untrusted/unknown data, as those will automatically be escaped and avoid SQL injection.
var db = require('db');
var engine = require('engine');
var helpers = require('helpers');
// see https://forum.sinusbot.com/threads/mysql-varchar-returned-as-array-of-ascii-chars.7459/#post-42918
function parseString(numberBuffer) {
if (!Array.isArray(numberBuffer)) return "";
const bytewriter = helpers.newBytes();
numberBuffer.forEach(num => bytewriter.append(helpers.bytesFromHex(num.toString(16))));
return bytewriter.toString();
}
var dbc = db.connect({ driver: 'mysql', host: '127.0.0.1', username: 'demo', password: 'blah', database: 'foo' }, function(err) {
if (err) {
engine.log(err);
}
});
if (dbc) dbc.exec("INSERT INTO blah (foo, foo2) VALUES (?, ?)", 'bar', 'bar2');
if (dbc) dbc.query("SELECT * FROM blah", function(err, res) {
if (!err) {
res.forEach(function(row) {
engine.log(parseString(row.foo));
});
} else {
engine.log(err);
}
});
(DBParams)
Connection parameters
(dbConnectCallback)
Callback gets called on success / error;
If an error occured, exactly one parameter containing the error will be handed to the callback
DBConn?
:
Database connection or null if failed
This module is protected. This means that you need to add 'fs'
to requiredModules
in your script's Manifest in registerPlugin in order to use it.
This module is protected. This means that you need to add 'graphics'
to requiredModules
in your script's Manifest in registerPlugin in order to use it.
The best example on how to use the graphics module is the Avatar banner script by Filtik.
Setbanner sets the avatar of the sinusbot client.
boolean
:
success
graphics.setBanner('banner', {
"format": "png",
"width": 260,
"height": 120,
"layers": [
// FIXME: add layers here
]
}, function() {
engine.setAvatarFromBanner('banner.png');
});
Generates a new CryptoKeypair.
CryptoKeypair
:
New
CryptoKeypair
.
Loads a keypair from bytes and returns it as a CryptoKeypair.
(BytesWriter)
Keypair bytes.
CryptoKeypair
:
(BytesWriter)
Secret
(BytesWriter)
Message
BytesWriter
:
Encrypted message
(BytesWriter)
Secret
(BytesWriter)
Message
BytesWriter
:
Decrypted message
(string)
(BytesWriter)
The master password from which a derived key is generated.
(BytesWriter)
Salt.
(number)
Number of iterations.
(number)
Desired bit-length of the derived key.
BytesWriter
:
Keypair bytes
Returns a given number of random bytes.
(number)
Number of random bytes to return
BytesWriter
:
Random bytes
Note: if the client is inivisible to the bot, some fields might not be available.
Returns the clients' servergroups
Array<ServerGroup>
:
Returns the clients' channelgroup
ChannelGroup
:
Adds a client to a specific ServerGroup
((ServerGroup | string | number))
Servergroup the client should be added to
Removes a client from a specific ServerGroup
((ServerGroup | string | number))
Servergroup the client should be removed from
Moves a client to another channel
*Note: This can also be used to disconnect a discord bot-instance from the voice chat with backend.getBotClient().moveTo('')
.
Updates multiple channel parameters at once
(ChannelParams)
Assigns a client to a channel group
(Client)
(ChannelGroup)
Gets the permissions for the channel from the server - this is an expensive call as the permissions are not cached
Array<Permission>
:
Adds/sets a new permission on the channel; you need to use the setters and then call save() to apply - can also be used to remove a permission by delete() afterwards
(string)
id of the permission to add; can also be supplied as name like i_channel_needed_join_power
Permission
:
Gets the messages of a discord channel.
(function)
(error, messages)
boolean
:
Returns the privileges of the user
number
:
Privileges of the user
const ENQUEUE = 1 << 13;
const SKIP_QUEUE = 1 << 14;
const ADMIN_QUEUE = 1 << 15;
const PLAYBACK = 1 << 12;
const START_STOP = 1 << 8;
const EDIT_BOT_SETTINGS = 1 << 16;
const LOGIN = 1 << 0;
const UPLOAD_FILES = 1 << 2;
const DELETE_FILES = 1 << 3;
const EDIT_FILES = 1 << 4;
const CREATE_AND_DELETE_PLAYLISTS = 1 << 5;
const EDIT_PLAYLISTS = 1 << 7;
const EDIT_INSTANCES = 1 << 17;
const EDIT_USERS = 1 << 9;
function hasPlaybackPermission(user) {
// returns true if user has playback permission
return (user.privileges() & PLAYBACK) != 0
}
handles channel, channelgroup and servergroup permissions; mainly for TS3
Gets the permissions for the channelgroup from the server - this is an expensive call as the permissions are not cached
Array<Permission>
:
Adds/sets a new permission to the channelgroup; you need to use the setters and then call save() to apply - can also be used to remove a permission by delete() afterwards
(string)
id of the permission to add; can also be supplied as name like i_channel_needed_join_power
Permission
:
Gets the permissions for the servergroup from the server - this is an expensive call as the permissions are not cached
Array<Permission>
:
Adds/sets a new permission to the servergroup; you need to use the setters and then call save() to apply - can also be used to remove a permission by delete() afterwards
(string)
id of the permission to add; can also be supplied as name like i_channel_needed_join_power
Permission
:
Track in a Playlist
This type is passed to a (api|public):<eventName>
-event,
see api:<eventName>
or public:<eventName>
for more.
Array<PlaylistTrack>
:
List of all tracks inside the given playlist
Sends data over the connection
Closes the current connection
Use this, if you expect a result set.
NOTE: Strings will be returned as byte arrays to be binary safe; to convert to actual strings, please follow this post: https://forum.sinusbot.com/threads/mysql-varchar-returned-as-array-of-ascii-chars.7459/#post-42918
(string)
(any?)
Zero or more parameters; e.g. for mysql, ? in the queryString will be replaced with these parameters
(dbQueryCallback)
Callback is called after the query has finished.
Use this insted of query if you don't expect a result
(string)
(any?)
Zero or more parameters; e.g. for mysql, ? in the queryString will be replaced with these parameters
(dbQueryCallback?)
number
:
UNIX file permission mode
Parameter of the message event callback.
Create a reaction for the message.
emoji
takes the form of name:id
for custom guild emoji, or Unicode characters.
Requires the READ_MESSAGE_HISTORY
permission.
Additionally, if nobody else has reacted to the message using this emoji,
this requires the ADD_REACTIONS
permission to be present on the current user.
(function?)
boolean
:
success
Deletes all reactions on a message. This requires the MANAGE_MESSAGES
permission.
(function?)
boolean
:
success
Either ExtendedDiscord or ExtendedTS3
Sends a presence or status update.
(object)
Name | Description |
---|---|
status.game object?
|
Activity |
status.game.name string?
|
Activity's name |
status.game.type number?
|
Activity's type: 0 (game), 1 (streaming), 2 (listening) |
status.game.url string?
|
Only https://twitch.tv/ urls work. |
status.status string
|
Status Type . Either online, dnd, idle, invisible or offline. |
status.afk boolean
|
Whether or not the client is afk. |
status.since number?
|
Unix time (in milliseconds) of when the client went idle, or null if the client is not idle. |
const backend = require("backend")
// => playing hide and seek
backend.extended().setStatus({
since: 0,
game: {
name: "hide and seek",
type: 0,
},
status: "online",
afk: false
})
const backend = require("backend")
// => set status to 'do not disturb'
backend.extended().setStatus({
since: 0,
game: {},
status: "dnd",
afk: false
})
Get a channel by ID. Returns a channel object.
(string)
Update a channels settings. Requires the MANAGE_CHANNELS
permission for the guild.
Delete a channel, or close a private message.
Requires the MANAGE_CHANNELS
permission for the guild.
Deleting a category does not delete its child channels;
they will have their parent_id removed and a Channel Update Gateway event will fire for each of them.
Returns the messages for a channel.
If operating on a guild channel, this endpoint requires the VIEW_CHANNEL
permission to be present on the current user.
If the current user is missing the READ_MESSAGE_HISTORY
permission in the channel then this will return no messages (since they cannot read the message history).
Returns a specific message in the channel.
If operating on a guild channel, this endpoint requires the READ_MESSAGE_HISTORY
permission to be present on the current user.
Post a message to a guild text or DM channel.
If operating on a guild channel, this endpoint requires the SEND_MESSAGES permission to be present on the current user.
If the tts field is set to true, the SEND_TTS_MESSAGES
permission is required for the message to be spoken.
Sends a raw http request to the discord API and therefore allows potentially unsafe and arbitrary API calls. Check the discord documentation for available API calls.
Important: In previous SinusBot versions (1.0.0-beta.6 or older) this method was protected and only works if requiredModules: ['discord-dangerous']
is set in the script manifest.
Retrieves TeamSpeak Server Info
TeamSpeakServerInfo
:
TeamSpeakServerInfo Object for current server
Retrieve Extended TeamSpeak Server Info
This will fire a serverinfo_int event with a TeamSpeakExtendedServerInfo object as callback parameter.
boolean
:
success
See backend.extended().requestExtendedServerInfo().
Returns Keypair bytes.
BytesWriter
:
Keypair bytes
(BytesWriter)
BytesWriter
:
Type: object
Type: object
(Channel?)
: Old channel (or undefined if the client just got online/changed visibility)
(Channel?)
: New channel (or undefined if the client just went offline/changed visibility)
(Client)
: Client that was moved
(Client)
: Client that invoked the move
(string?)
: move/ban/kick message (TS3; since 1.0.0-beta.6)
Used to update or create a channel; When creating a channel parent and name are mandatory for TS3; When updating a channel parent will be ignored (use moveTo instead)
Type: object
(string)
: Displayname of the channel; mandatory on create
((Channel | number | string))
: Parent channel (you can also use the channelId); ignored on update, mandatory on create
(string)
(string)
(string)
(number)
: See codec types for explanation
(number)
(boolean)
(boolean)
(number)
(number)
(boolean)
: Whether the channel is the default channel
(number)
: TS3 only
(number)
: TS3 only
(number)
: TS3 only
Type: object
(Client)
: Client that has been added / removed
(Client)
: Client that added client to the group
(ServerGroup)
: Server Group
Type: object
Type: object
Type: object
Type: object
Type: Function
(string?)
If an error occured, exactly one parameter containing the error will be handed to the callback.
Type: Function
(string?)
If an error occured, exactly one parameter containing the error will be handed to the callback
Type: Function
(string?)
Gets called with two parameters, err and result - both are mutually exclusive. Result contains an array of rows, each containing an object with the column names as key.
Type: Function