revolt-bot-base documentation

Jump to section

Tool to simplify the creation of basic revolt bots.

Links:
GitHub | NPM

Install

$ npm install @astronomyoverdrive/revolt-bot-base

(This will also install ws)

Configure bot

Must be before commands
ConfigureBot({
  botToken: "TOKEN",
  botUserId: "USER_ID",
  serverId: "SERVER_ID",
  APILogs: false,
  chatLogs: "",
  modLogs: "",
  prefix: "",
  removeCaller: false,
  badWords: [],
  blockEmbeds: false,
  blockAttachments: false,
  badWordLevel: 3,
  embedLevel: 2,
  attachmentLevel: 1
});

botToken = Your bots token. String
botUserId = Your bots User ID. String
serverId = Your servers Server ID. String
APILogs = Log socket events & API responses? Boolean
chatLogs = Log messages to separate channel? String, either Channel ID or empty to disable
modLogs = Log bot kick/ban actions to separate channel? String, either Channel ID or empty to disable
prefix = Prefix for commands. String
removeCaller = Remove message that triggered a command? Boolean
badWords = Words to automod. Array with lowercase strings or regex, /\bword\b/ to match whole words
blockEmbeds = Should bot automod embeds? Boolean
blockAttachments = Should bot automod attachments? Boolean
badWordLevel = What action to take against users using bad words? Integer, 1-3*
embedLevel = What action to take against users using embeds? Integer, 1-3*
attachmentLevel = What action to take against users using attachments? Integer, 1-3*
* 1 = Warn, 2 = Kick, 3 = Ban

Register "Send" action command

RegisterCommand({
  usePrefix: true,
  command: "command",
  action: "Send",
  allowedRoles: [],
  allowedChannels: [],
  targetChannel: "",
  contents: ""
});

usePrefix = Require prefix for this command? Boolean
command = What should the actual command be? String
action = What action should the command trigger? String, valid action
allowedRoles = What roles can use this command? Array with Role IDs or empty to allow everyone
allowedChannels = Where can this command be used? Array with Channel IDs or empty to allow it everywhere
targetChannel = Where should the message be sent? String, either Channel ID or empty to use same channel as sender
contents = What text to send? String with message or empty string to use the text after "!command" from sender

Register "Remove" action command

Uses "[command] [message-link]" syntax
RegisterCommand({
  usePrefix: true,
  command: "command",
  action: "Remove",
  allowedRoles: [],
  allowedChannels: []
});

usePrefix = Require prefix for this command? Boolean
command = What should the actual command be? String
action = What action should the command trigger? String, valid action
allowedRoles = What roles can use this command? Array with Role IDs or empty to allow everyone
allowedChannels = Where can this command be used? Array with Channel IDs or empty to allow it everywhere

Register "Poll" action command

RegisterCommand({
  usePrefix: true,
  command: "command",
  action: "Poll",
  allowedRoles: [],
  allowedChannels: [],
  targetChannel: "",
  contents: ""
});

usePrefix = Require prefix for this command? Boolean
command = What should the actual command be? String
action = What action should the command trigger? String, valid action
allowedRoles = What roles can use this command? Array with Role IDs or empty to allow everyone
allowedChannels = Where can this command be used? Array with Channel IDs or empty to allow it everywhere
targetChannel = Where should the message be sent? String, either Channel ID or empty to use same channel as sender
contents = What text to send? String with message or empty string to use the text after "!command" from sender

Register "AddRole" action command

Currently only applies the role to the sender of the command
RegisterCommand({
  usePrefix: true,
  command: "command",
  action: "AddRole",
  allowedRoles: [],
  allowedChannels: [],
  contents: ""
});

usePrefix = Require prefix for this command? Boolean
command = What should the actual command be? String
action = What action should the command trigger? String, valid action
allowedRoles = What roles can use this command? Array with Role IDs or empty to allow everyone
allowedChannels = Where can this command be used? Array with Channel IDs or empty to allow it everywhere
contents = What role to add? String with Role ID

Register "Kick" action command

Uses "[command] <@userid> reason" syntax
RegisterCommand({
  usePrefix: true,
  command: "command",
  action: "Kick",
  allowedRoles: [],
  allowedChannels: []
});

usePrefix = Require prefix for this command? Boolean
command = What should the actual command be? String
action = What action should the command trigger? String, valid action
allowedRoles = What roles can use this command? Array with Role IDs or empty to allow everyone
allowedChannels = Where can this command be used? Array with Channel IDs or empty to allow it everywhere

Register "Ban" action command

Uses "[command] <@userid> reason" syntax
RegisterCommand({
  usePrefix: true,
  command: "command",
  action: "Ban",
  allowedRoles: [],
  allowedChannels: []
});

usePrefix = Require prefix for this command? Boolean
command = What should the actual command be? String
action = What action should the command trigger? String, valid action
allowedRoles = What roles can use this command? Array with Role IDs or empty to allow everyone
allowedChannels = Where can this command be used? Array with Channel IDs or empty to allow it everywhere

Register "Custom" action command

For more advanced users
RegisterCommand({
  usePrefix: true,
  command: "command",
  action: "Custom",
  allowedRoles: [],
  allowedChannels: [],
  contents: `JavaScript-code`
});

usePrefix = Require prefix for this command? Boolean
command = What should the actual command be? String
action = What action should the command trigger? String, valid action
allowedRoles = What roles can use this command? Array with Role IDs or empty to allow everyone
allowedChannels = Where can this command be used? Array with Channel IDs or empty to allow it everywhere
contents = Code to run when called. String
-Available variables (all are strings):
UserId - Id of the user who called the command
UserChannel - Id of the channel the command was called from
UserText - Everything after "!command "
-Available functions (all items in the arrays are strings):
makeRequest("Send", [channelId, messageText]);
makeRequest("Kick", [serverId, userId, reasonMessage]);
makeRequest("Ban", [serverId, userId, reasonMessage]);
makeRequest("AddRole", [serverId, userId, roleId]);
-Tip:
Use prefixes on your variable/function names to avoid overwriting the ones from the bot, e.g. function my_Function()

Register recurring message

RegisterRecurring({
  Day: [],
  Hour: [],
  Minute: [],
  Channel: "channelid",
  Message: "message"
});

Day = What day(s) to send this message? Array with integers, 0-6 with 0 = Sunday and 6 = Saturday.
Hour = What hour(s) to send this message? Array with integers, 0-23.
Minute = What minute(s) to send this message? Array with integers, 0-59.
Channel = Where should the message be sent? String with Channel ID.
Message = What text to send? String with message.

Start bot

Must be after commands
startBot();

Example bot

const bot = require("@astronomyoverdrive/revolt-bot-base");

bot.ConfigureBot({
  botToken: "YOUR_BOT_TOKEN", /* Found in Settings -> My Bots */
  botUserId: "YOUR_BOT_USER_ID", /* Found in Settings -> My Bots */
  serverId: "YOUR_SERVER_ID", /* Right-click server -> Copy server ID */
  APILogs: false, /* Don't show events/responses in terminal */
  chatLogs: "", /* Don't keep a log of users messages */
  modLogs: "", /* Don't keep kick/ban logs */
  prefix: "!", /* Use ! as command prefix */
  removeCaller: true, /* Remove the message that triggered the command */
  badWords: [/\bemacs\b/, "vscode"], /* Remove messages with these words */
  blockEmbeds: true, /* Remove messages trying to embed links */
  blockAttachments: true, /* Remove messages using attachments */
  badWordLevel: 3, /* Ban users using bad words */
  embedLevel: 1, /* Warn users using embed */
  attachmentLevel: 1 /* Warn users using attachment */
});

/* Get Role IDs with Server settings -> Roles -> ROLE ID */
/* Get Channel IDs with Right-click channel -> Copy channel ID */
/* Get User IDs with Right-click user -> Copy user ID */

/* !live */
bot.RegisterCommand({
  usePrefix: true,
  command: "live",
  action: "Send",
  allowedRoles: ["STAFF_ROLE_ID"],
  allowedChannels: ["STAFF_BOT_CHANNEL_ID"],
  targetChannel: "LIVE_CHANNEL_ID",
  contents: "<@USER_ID> is now live at [TEXT](URL)"
});

/* !announce what to announce */
bot.RegisterCommand({
  usePrefix: true,
  command: "announce",
  action: "Send",
  allowedRoles: ["STAFF_ROLE_ID"],
  allowedChannels: ["STAFF_BOT_CHANNEL_ID"],
  targetChannel: "SERVER_ANNOUNCEMENTS_CHANNEL_ID",
  contents: ""
});

/* !poll what to vote on */
bot.RegisterCommand({
  usePrefix: true,
  command: "poll",
  action: "Poll",
  allowedRoles: [],
  allowedChannels: [],
  targetChannel: "",
  contents: ""
});

/* !remove (message-link) */
bot.RegisterCommand({
  usePrefix: true,
  command: "remove",
  action: "Remove",
  allowedRoles: ["STAFF_ROLE_ID"],
  allowedChannels: ["STAFF_BOT_CHANNEL_ID"]
});

/* !kick <@userid> reason */
bot.RegisterCommand({
  usePrefix: true,
  command: "kick",
  action: "Kick",
  allowedRoles: ["STAFF_ROLE_ID"],
  allowedChannels: ["STAFF_BOT_CHANNEL_ID"]
});

/* !ban <@userid> reason */
bot.RegisterCommand({
  usePrefix: true,
  command: "ban",
  action: "Ban",
  allowedRoles: ["STAFF_ROLE_ID"],
  allowedChannels: ["STAFF_BOT_CHANNEL_ID"]
});

/* Accept */
bot.RegisterCommand({
  usePrefix: false,
  command: "Accept",
  action: "AddRole",
  allowedRoles: [],
  allowedChannels: ["WELCOME_CHANNEL_ID"],
  contents: "MEMBER_ROLE_ID"
});

/* !quote text to quote */
bot.RegisterCommand({
  usePrefix: true,
  command: "quote",
  action: "Custom",
  allowedRoles: [],
  allowedChannels: [],
  contents: `
   const my_SendTo = UserChannel;
   const my_Year = new Date().getFullYear();
   const my_SendText = '"'+UserText+'" - <@'+UserId+'>, '+my_Year;
   makeRequest("Send", [my_SendTo, my_SendText]);
  `
});

/* !add 10 5 */
bot.RegisterCommand({
  usePrefix: true,
  command: "add",
  action: "Custom",
  allowedRoles: [],
  allowedChannels: [],
  contents: `
   const my_SendTo = UserChannel;
   const my_Numbers = UserText.split(" ");
   const my_SendText = Number(my_Numbers[0]) + Number(my_Numbers[1]);
   makeRequest("Send", [my_SendTo, String(my_SendText)]);
  `
});

/* Friday message */
bot.RegisterRecurring({
  Day: [5],
  Hour: [0],
  Minute: [0],
  Channel: "GENERAL_CHANNEL_ID",
  Message: "It's finally friday!"
});

/* Twelve reminder */
bot.RegisterRecurring({
  Day: [0, 1, 2, 3, 4, 5, 6],
  Hour: [0, 12],
  Minute: [0],
  Channel: "GENERAL_CHANNEL_ID",
  Message: "The clock is now twelve!"
});

bot.startBot();