Skip to content

Connects MTA:SA servers and Discord channels by sending messages/commands back and forth

License

Notifications You must be signed in to change notification settings

botder/mtasa-discord-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mta-discord-bot

Connects MTA:SA servers and Discord channels by sending messages/commands back and forth.
Note: The recent code update has breaking changes to your config.json, please replace server with guild, thanks.

Installation

MTA:SA

The discord resource requires the socket module on your MTA:SA server. You can find the installation guide and the binaries on the MTA wiki.

The resources themselves require no special setup, you only have to edit the discord/config.xml to fit your setup. The resource discord is responsible for message transfer between your MTA:SA server and the Discord relay. On the other hand, discord-events is listening for events on the MTA:SA server to send these to the relay through the discord resource.

mta/discord/config.xml

<discord>
    <channel>name-of-your-channel</channel>
    <passphrase>equal-to-the-server-passphrase</passphrase>
    <hostname>localhost</hostname>
    <port>8100</port>
</discord>

Relay

The relay server connects to Discord as a bot user; and starts a socket server listening for connections. I never bothered to keep the code compatible with older releases of node.js, which might be an issue on some distributions.

The relay code needs a little preparation before you can run it. You have to run the command npm install in the src directory to download the node.js modules required by the application. Furthermore, you have to copy the file src/example.config.json to src/config.json and edit it to fit your setup (the passphrase and port must be equal to the discord config.xml on your MTA:SA server).

You can start the relay with node app.js, but you should consider using pm2 to restart the relay automatically on crashes.

src/example.config.json

{
    "port": 8100,
    "passphrase": "key",
    "guild": "guild.id",
    "bots": [{
        "channel": "channel.name",
        "token": "bot.token"
    }]
}

Notes

Discord Bots

Note Make sure your bot account has the MESSAGE CONTENT INTENT permission, because otherwise you will only see empty messages coming from Discord (in MTA:SA).

image

This application doesn't magically add your bot(s) to your guild(s). You (better said: the guild owner) have to authorize every bot user. Navigate to your bot application on the following page and note the client id:

https://discord.com/developers/applications

Then continue to replace the client_id field in the URL below and navigate to that page:

https://discord.com/api/oauth2/authorize?scope=bot&permissions=0&client_id=<your_client_id_here>

Proceed by authorizing the bot for the guild of your choice and you're done.

About

Connects MTA:SA servers and Discord channels by sending messages/commands back and forth

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published