Search code examples
discorddiscord.jsself-hosting

How does hosting a Discord Bot work since there is no port forwarding, and you do not know my ip address?


So i've been making and using my Discord bot (written in javascript) for about 5 months, ive learnt quite a bit and it works nicely. Only thing is, i dont understand how it actually works in terms of hosting? I have it running at home 24/7 on a raspberry pi but i mean, and ive hosted websites at home too, so i've done port forwarding etc for my websites, but you dont have to do that with a discord bot? Can anyone explain how it all works?


Solution

  • Discord does not connect to your network, but you connect to Discord's network (the API). You ask the Discord API for information, you then do something with this information and you send something back. Your bot is not a server, the Discord API is a (web) server. You don't have to port forward to use Discord as a normal user, or to browse the web either, do you?

    The reason that you have to port forward when you host a website, is because your Raspberry Pi is the web server, and the visitors connect to you.

    There is a lot to networking, so this just scratches the surface on how you connect to Discord. If you want to learn more, I would recommend taking a CCNA course or watching some YouTube videos about it.