Skip to content
Tim K edited this page Jun 2, 2017 · 9 revisions

Using Discord Spoiler Bot

This section will talk about basic usage of the bot and how you can configure some advanced features. For more information, see Configuration.

Basic Usage

Create a file called index.js and put the following inside:

'use strict';

const SpoilerBot = require('discord-spoiler-bot');

let config = {
    token: 'you_secret_token_here',
};

let bot = new SpoilerBot(config);
bot.connect();

Note the config object, it is required for Discord Spoiler Bot to work. Once you save the file, you can run your bot using Node.js:

$ node index.js

Specifying channels spoiler bot should listen to

By default, spoiler bot listens to all channels. If you want spoiler bot to only listen to a couple of specific channels, add a include property to your config:

let config = {
    token: 'you_secret_token_here',
    // List of channel IDs to listen to
    include: [
        '241271400869003265',
        '241512070854606848'
    ],
};

If instead you want the bot to listen to all channels but the ones you wish to exclude, add exclude array to you config:

let config = {
    token: 'you_secret_token_here',
    // Bot will listen to all channels BUT the ones below
    exclude: [
        '241271400869003265',
        '241512070854606848'
    ],
};

Note: You cannot specify both exclude and include at the same time.

Specifying who can mark other messages as spoilers

When spoiler bot is enabled, you can mark someone else's messages are spoilers using <message-id>:spoils:<topic> format. To allow everyone to mark someone else's messages are spoilers, set markAllowAll to true:

let config = {
    token: 'you_secret_token_here',
    markAllowAll: true,
};

If you want to allow users with certain Roles attached to them, add markRoleIds to your config. This should be an array of strings where each string represents the ID of a role user should have. To find out the role ID, go to server settings, and for role you're interested in check Allow anyone to @mention this role. Then, in chat, type \@<role-name> (e.g. if your name is called Moderator type \@Moderator). This will give you a string looking something like this: <@&285235614805262339>. The integer part is the role ID that you want.

You can also specify users that can mark spoilers by placing user IDs in markUserIds. If both markRoleIds and markUserIds, spoiler bot allows user to mark spoilers as long as they satisfy any of these conditions.

let config = {
    token: 'you_secret_token_here',
    // Bot will allow users with the following roles to mark spoilers
    markRoleIds: [
        '241271400869003265',
        '241512070854606848'
    ],
    // Bot will allow users with the following IDs to mark spoilers
    markUserIds: [
        '241271400869003265',
        '241512070854606848'
    ],
};

Specifying maximum amount of lines

By default, if the spoiler content is taking up more than 6 lines, it's trimmed to 6 lines an an ellipsis is inserted at the end of last string. You can increase (or decrease) this limit by setting maxLines to an integer greater than zero. Below I set it to 20, which will result in a very long, hardly readable GIF.

let config = {
    token: 'you_secret_token_here',
    maxLines: 20,
};

Custom spoiler message format

This feature is already working and I will try to complete this section as soon as possible.

Custom spoiler GIF appearance

You can customise the appearance of spoiler GIFs by adding a gif property to your config. For example, the following config will reproduce the default GIF appearance:

let config = {
    token: 'secret_token_here',
    gif: {
        margin: 10,
        width: 400,
        lineHeight: 40,
        placeholderText: '( Hover to reveal spoiler )',
        fontSize: '13px',
        colours: {
            background: '#3c3f44',
            stroke: '#b2ac94',
            text: '#c0ba9e',
            placeholder: '#8c8775',
        }
    },
};

If you leave out one of the GIF config properties the default will be used. I think I've picked the optimal values for margin, font size, width and line height so I'd recommend leaving them as-is.

Using external bot instance

If you follow the basic usage instructions above, spoiler bot will create a new Client instance from discord.js library. If you already have an instance of Client from discord.js or discord.io libraries running and want to avoid duplicating the bot, you can pass the existing instance as client in the config object.

E.g. for discord.js:

'use strict';

const Discord = require('discord.js');
const SpoilerBot = require('discord-spoiler-bot');

let client = new Discord.Client();
client.login('your_token_here');

let config = {
    client: client,
};

let bot = new SpoilerBot(config);
bot.connect();

Or for discord.io:

'use strict';

const Discord = require('discord.io');
const SpoilerBot = require('discord-spoiler-bot');

let client = new Discord.Client({
    autorun: true,
    token: 'your_token_here'
});

let config = {
    client: client,
};

let bot = new SpoilerBot(config);
bot.connect();
Clone this wiki locally