Discord and Matrix!? How to Bridge Your Discord Server to Matrix-Synapse

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everybody and welcome back to Jim's Garage since putting out my Matrix synapse Home Server video I've had quite a lot of feedback asking for Bridges now for those of you who didn't watch that video you can find it on my channel and Matrix is basically an open source end-to-end encrypted decentralized communications platform it covers things like messaging voice calls recording conferencing and a whole lot more because the protocol is extensible and you can visit the website to find out more about that one of the key things that's supported off the bat are bridges now Bridges much like joining two landmasters or a way to join two applications and today I'm going to show you how to connect Discord to Matrix so that means all that you need is a Discord account you don't even need to have Discord installed once you set up the bridge and so you might be thinking well what does this allow surely the functionality is not very good well it's pretty much much there you're not going to be able to do voice and video calls but you could do that anyway within Matrix so it will allow things like standard messaging so you will be able to send a message on Matrix and it will show up in Discord as though you have sent it because the way that we use web Hooks and the API it will be using your Discord account to send that message so everyone in Discord they won't even know that you sent it from Matrix and vice versa anybody who sends a message within the Discord Channel you'll also receive that on Matrix and this is a great way to get people into the Matrix ecosystem without losing some of the functionality that they want or are accustomed to now thankfully the process for setting this up is pretty straightforward however bit like my previous video there are methodical steps that we need to follow so as always I'll provide you with all of the config files on my GitHub will have a quick run through them and then I'll show you on screen how to do this step by step so at the end of this video you'll have a Discord server connected to your Matrix client and you'll be able to view and send messages from Matrix without ever needing to go into Discord again and also on top of that it's not just one server you could Bridge any server that you want so let's hop into the configuration and get on with it so heading over to the Matrix website and looking at the bridges you can see here that there's three options for setting up a bridge now these are in various states of development as you can see from the notes on screen this one here being in Alpha but the two ones that I recommend are either the Matrix app service Discord and that uses a Discord bot that you'll see in your Discord Channel or the male tricks I assume that's how you pronounce that Discord bot and this is the one that I've used because I find it really straightforward to set up it also seems to be regularly updated and supported so let's hop into the documentation for this and have a quick look so on the GitHub page be sure to give it a start let's have a look through the great thing here is that there's a Docker installation for this so let's click on Docker and view the instructions and much like in a previous video we need to run the container first to generate a configuration file we need to tweak the configuration file we need to mount that back into the container and then spin it up and this will also be a multi-container deployment because we need the maltix Discord bridge and we also need a supporting postgres database so here's the docker compose file that maltrex Discord provides but as I said we require a database to be set up now you can use an existing database as long as you create a new table within that database and you could then later specify that within the config file to use it but I'm going to assume that you don't have one and there's no harm in running two databases it's just a little bit of a waste of resources but it's not a big deal so I'll show you a Docker compose file where we've got both of those set up we'll spin it up and then we'll go and get the config file so heading over to my GitHub we can see the two containers and the compose file here so the first container we've got is the maotrix Discord bridge now this is the bit that's going to be doing the bridging so we need to deploy this container first to create a configuration file now just looking through this compose file there's nothing out of the ordinary we need to specify the volume amount so this is where it's going to spit out the configuration file and once we've tweaked the configuration file and re-upped the container it will also print out the registration yaml we'll come on to that in a moment we're going to expose a port for this service now you could put this within your existing synapse Docker compose file and you could just reference it using the DNS name IE Matrix Discord but I'm going to assume that you're doing this outside of it or you want to keep the compose file separate and in my instance I'm actually running the Matrix server within kubernetes so I need some way to be able to externally reference this so here we specified a port and much like in a previous video we've created The Matrix Discord Network this is a virtual Network within Docker and the next container which is the database we're going to sit that on this virtual Network so that Matrix Discord can talk to our database but nothing else will be able to reach it now that's good for security and it means that we can also use the friendly name of maotrix Discord DB instead of having to remember IP addresses so just looking through this it's a standard postgres 15 database it's the same one that we used for the Matrix synapse installation and as before we just need to specify a few parameters we need to create a user for the database we need to create a password and as I put in the comment please do make sure that you change this and you will need to use this later within the configuration file but if you've got it in the compose you should be able to copy and paste and we need to create the database itself in this case I've called it Matrix Discord and we need to run the initialization arguments which you can see on screen again because we want persistence within the database we need to use a volume Mount And as I've already mentioned we're going to stick this on the network of Matrix Discord and we're going to expose it on Port 5432 so now that we have the compose file let's copy that over to our Docker host and let's deploy the container now to bring this container up we simply run sudo Docker compose ob--d and as I stated the first time we run this is going to generate some configuration files that we need to change so don't worry that it's not working when you first do this the database however should set up and should be set as listening so let's go ahead and run that and then let's check out the configuration file it creates now if everything goes to plan you should receive a config.yaml file in the volume Mount that you specified now ignore the registration this is from my live deployment we'll get the registration file generated in a moment so if you open the config file it looks like this over here on the GitHub page and there's a few things that we need to change first thankfully there aren't many things you need to get this up and running the first thing you need to change here is your address so this will be your public address or it could be a separate internal address that you've got the public one is actually specified below but in my instance it's the same it's matrix.jimsgarage dot Co dot UK the domain is the same as the home server name and again in my instance this is matrix.jimsgarage dot Co dot UK the next section that we have to change is in the app services and it's chiefly the address so this is the address of the Matrix bridge that you're going to run so that's either your Docker IP and port or you might want to specify a DNS name for this and put it in your DNS resolver perhaps pie hole for example the next bit is important and that's the database configuration so the bit that we need to change here is the URI now you need to take your user from your Docker compose file you need to take the password from the docker compose file you need to change the host to be the name of the service I.E Matrix Dash Discord DB and you need to change the database name so the slash database to be Matrix Dash Discord so I'll put an example on screen below and you can copy that and change it to your setup so my URI would look like this and these details are taken from the docker compose file so Matrix Discord is my user here's my long password the at is maltrex Discord DB which is the DNS name within Docker for the container and the database I want to connect to is maatrix Discord so once you've configured the database section there's only really one extra area that we need to focus on and that's down near the bottom in the permissions section now I do recommend you go through and look at all of these settings and tailor it to your requirements and more basically just to understand sort of what's going on within the bridge so the permissions here are for what people can do with the bridge so the first one here any relay that means that anyone on your server can talk through the relay the second one means that people can use the actual Discord bot to bridge their account I.E they can use the bridge and the third one is to specify your admin user so in this case it would be star for the Relay I want everyone to be able to use the relay I've set matrix.gymsgarage.com for the user so anyone on my Home Server can use it and then I put at gym colon matrix.jimsgarage.co.uk as the admin because I want my user to be able to have administrative commands with the bot so once you've saved that configuration file you need to deploy the container again and that's the same as doing sudo Docker compose up Dash D dash dash Force Dash recreate or you could delete the container and just re-up it again the same way as before now this time with a configuration file mounted it will spit out the registration yaml now this is the part that you need to then copy into your synapse Home Server and reference so we have the configuration for the Discord bot but now we need to register it with the sign up server so let's go and do that now let's run this container and have a look at the registration file now after running that command you can see that my registration file is in the configuration file I mentioned that I'd done this earlier but this is exactly what it will look like so you'll also notice that this registration file has a different user to the one that you're logged in with so you won't be able to edit this directly through winscp so you can either change the ownership of that file or simply sudo nanowit within your terminal like so navigate to the compose volume Mount location and do a sudo Nano registration.yaml now thankfully this is quite a small file so it doesn't look too bad looking at a nano and it's pretty straightforward we can see that it's generated a couple of tokens and it sets some namespaces and users so all we need to do now is to copy the contents of this file change the home server.yaml file which we did previously and make a reference to this registration yaml so let's go ahead and do that now so I've navigated to my Docker synapse folder this is the volume Mount location for my synapse Home Server and there's two ways you could do this you could go into the terminal and do a sudo CP command to copy the registration file from your mailtrix Discord volume Mount to your synapse volume Mount also bear in mind if you do that you would need to change the permissions so that synapse server can read this or you could simply copy the contents of this file go to your signups file right click new file registration.yaml and then just paste the content in here and hit save now that it's saved we have it in the root directory we simply need to change the home server.yaml file to reference this registry your file so let's go and do that now quickly and thankfully it's as simple as pasting the following command we're saying that we want an app service and we want the config file so an app service config file and we're specifying that it's in slash data slash registration.yaml which is a file we've just created and if we look at the docker compose file for synapse we know that we're mounting the data folder to this one over here which is our winscp so anything we put in there is going to show up in the slash data file so we should be good to go so now if you make sure that your maotrix Discord bot is running we should simply need to restart our synapse server to pick up the new registration file so let's go and do that now so for me I'm running this in kubernetes so I could just scale this down to zero or delete the Pod and then it'll re-up with the registration file but if you're using this in Docker simply do a sudo Docker restart and then the container name or if you're in portana you can simply click the container and then just hit restart and it will do the same thing so hopefully when it restarts let's check the logs and see what's going on in there so I've just restarted my actual running production Matrix Discord Bridge just to prove to you what it should say so the key bit here is the bridge has started updating the bot profiles all of that and you can see that it's making connections to and from the database so that's great everything's up and running and you should receive some similar messages to that so fingers crossed now you have the bridge up and running is connected to your home Matrix synapse server but now we need to actually configure and talk to the bot now thankfully that couldn't be more straightforward so let's hop into element which is the client I'm using but whatever client you're deciding to use it's the same set of commands let's do that now so over on my element you can see that my Discord bridge is set up so I've linked this to my Discord chat it's for my Home Server stuff and you can see that it's pulled it in here under the Discord bot with all of the rooms that are available on my Discord channel so to get here we simply need to create a new chat so we click on home then we click Start new chat and we want to do it with the Discord Bridge bot so that's at Discord bot and then colon and your Matrix Home Server click go this will now put you into a chat with the Discord bot and do make sure that you say something to the bot otherwise it won't give you the instructions and it won't start the conversation so let's be friendly and say hello so when you send a message it will come back to you create the room all of that and you're now in a conversation with the bot so as you can see let's say help now that you've clicked help you get all of the commands for the bot but it's really straightforward to get this working so there are a few ways that you can authenticate with your Discord account through this Discord bot the easiest way is to do the login QR code so you simply need to say login Dash QR this will generate a QR code unfortunately I'm already logged in but this will display a QR code and you simply need to grab your Discord mobile application and scan the QR code accept it and then it will log you in as your user it's as simple as that if that doesn't work you can also use the login token method so that's login Dash token and then it will be a user and then paste your token now you can get the token quite easily by going into the console in the network tab on your browser and simply copy that into here now the bit that you'll be really interested in is how to bridge your Discord servers now thankfully that's really straightforward and it's here with the guilds and the command we need to type is guilds Bridge we want to set up a bridge and then as you can see here it takes an ID now where do we get the ID from well this is the ID of the server the Discord assigns the easiest way I've found to get this is to not use the Discord application but to log in through the Discord website and if you look in the URL you will see the slash for the Discord server and then a following slash if you're in any rooms within that server so that actually means you could just Bridge a single room or you could just Bridge the whole server I prefer to bridge the whole server and so we type in the guilds bridge and then we put the ID in here and then we do dash dash entire now that will Bridge the entire Discord server I.E it will bring up all of the rooms that you can see here on my screen so this is a replica of my Discord server and you can simply then join the ones that you want to join now when you run that command it will get a bit spammy on the left hand side here but that's just inviting the bot to each of those channels just simply click accept and then you'll be up and running any message that you post in your Matrix channel will be replicated within Discord and vice versa if you want to be able to see everybody's messages I.E messages from other users as well as yourself you need to configure a relay now a relay is just using the web hooks within Discord and it basically copies and pastes the messages to and from and to do that we simply need to head into a room on our Discord server you might need to join it first so we want to do exclamation mark Discord that's the command to invoke the bot we want to set a relay and we want to create a relay so if we hit return on this it's going to go away and now it's created a webhock for this Channel and we're in the gaming channel so if I send a message in here test hopefully if I go to my Discord Channel we'll now be able to see that message so let me just validate that now so over on my Discord let's have a look in the gaming channel let's click gaming and there we go there's the message that we sent in Matrix and I can send this back so if I say test in Discord I should get a pop-up in element to say that I've received it I did and I've also got it on my mobile device so thanks Jeffrey um let's head back onto my element and here you see that I get the message back from me and I also get Jeffrey with his interesting little Avatar as well so hopefully now you have everything working to go and Bridge all of your Discord channels into Matrix now the important bit here is that you understand that each user on your server will need to go through this process to be able to bridge their Discord channels into Matrix you can't do it for you and then share those channels with other users because remember you're logged in as you so if you did do that any messages that were sent would look like it's you and that might get you into some hot water so don't do that so thanks for watching Everybody hopefully this is going to give you all of the tools you need to be able to bridge your Discord with your Matrix server and hopefully transition people over from Discord to the lovely world of Matrix do bear in mind that the docker container that I deployed can also bridge to things like slack WhatsApp Telegram and many other things so have a look through that documentation and set up the bridges that you require for your community thanks for watching and as ever please comment like And subscribe and I'll see you on the next video take care everybody foreign [Music]
Info
Channel: Jim's Garage
Views: 3,631
Rating: undefined out of 5
Keywords: linux, docker, self hosted, privacy, proxmox, data privacy, private message, end to end encryption, encrypted messages, whatsapp end to end encryption, whatsapp privacy settings, whatsapp alternative, whatsapp security, encryption, element chat, what is whatsapp end to end encryption, encryption whatsapp, matrix protocol, synapse home server, federation, smtp, email, recaptcha, google captcha, gmail, android, ios, ubuntu, discord, discord server, discord bridge, discord matrix
Id: 0nnhSus7Aaw
Channel Id: undefined
Length: 21min 3sec (1263 seconds)
Published: Wed Aug 16 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.