Bot to cross-post messages between servers, similar to what the announcement channels do, but without having to be a Discord partner and with more control over what is published automatically.
This bot is written in Typescript, running as a Node.js package. To set it up, first install the dependencies and compile to vanilla Javascript, running
npm i && npm run build
from the root directory.
Copy the config.json.example
to data/config.json
and adjust to your liking. Tokens can be acquired from the Developer Portal when creating a new application.
Note that the Message Content Intent
needs to be enabled for your bot application on the developer portal!
When starting for the first time, you need to first register all commands with the app. To do so, you can run
node built/src/index.js --register
After setting up, you can run the bot using
node built/index.js
or
npm run run
From the root directory. You may want to put a service in place to automatically run the bot, as usual.
The crossposter features the following commands, all of them only available to the owner of the bot, as defined within the configuration file.
Lists all servers the bot instance is running on. No parameters.
Lists all active bridges. No parameters.
Removes a bridge by its ID. The only parameter is a numerical ID, which can be acquired from the listbridges
command.
Creates a new bridge from one server + channel to another. The parameters are as following:
- Name of the server from which the messages should be read. A list of servers the bot has access to can be acquired from
listservers
. - Name of the channel on the source server from which messages should be read. The channel must exist and the bot must be able to read from it, or the command will.
- Name of the server to which the messages should be forwarded.
- Name of the channel on the destination server where the messages should be written to. Again, that channel must exist.
- A descrimniator to determine whether a message will be forwarded over the bridge. Available discriminators are:
uid
the user ID of the user who posted the message. Use if you want to only forward messages from certain users.uname
the display name of the user who posted the message. Use if you want to only forward messages when their poster has a certain name. See below for RegEx usage.text
the text of the message. Useful if you only want to forward messages when they feature certain content. See below for RegEx usage.
- The regular expression which the descriminator must match. If anything should match, just pass
.
. - Mentions that should be preserved. These can be
users
,roles
, oreveryone
. That means for example, if you preserveroles
on a bridge, the bot will attempt to actually mention role in their forwarded post. Elsewise, roles will just appear as plain text without causing a notification for users. Note thateveryone
will preserve both@everyone
and@here
. You can combine these mentions by passing multiple values with a comma separator. I.e. passingusers,everyone
for this parameter will preserve mentions for users and@everyone
, but not for roles.
If any of the parameters in a command contains whitespace, you need to put qutoes around them.
Messages are only forwarded, if their discriminator matches a regular expression. The most simple case would be to have all messages from server A
in channel foo
forwarded to channel bar
on server B
:
createbridge A foo B bar text:.*
But it could also be used to only forward messages that start with a trigger word, like "ATTENTION":
createbridge A foo B bar text "^ATTENTION.*"
Or players whose display name indicate they belong to a certain guild (be aware that on most servers users can freely change their display name):
createbridge A foo B bar uname "\[EPIC\]"
would only forward messages from players with the tag "[EPIC]" in their display name.
You can mount a volume on /app/data
which should contain your config.json
and your database.db
file.