How to host your Discord bot 24/7 on an Android Device

Introduction

As most of us know that Glitch permanently banned all pinging services and everything related to them. Most of us also can’t afford buying Glitch subscription or using other services. However there is an great solution for that. So let’s get started.

What You Will Need

  • Android device (Needed to handle Termux).
  • Internet access (Needed to host our bot).
  • Termux (Needed to enable us to host our bot).
  • Code editor like QuickEdit and anWriter free. (Optional, but very useful for coding your bot).

Step By Step Instructions

  1. Open your File Manager.
  2. Create a folder named DiscordBOT.
  3. Create a file named index.js, and place it in the DiscordBOT folder.
  4. Write the following code to the index.js.
console.log("index.js has been executed");

const Discord = require("discord.js");
const client = new Discord.Client();

client.on("ready", () => {
  console.log("bot has logged into the account");
});

client.on("message", (message) => {
  if (message.author.bot) return;
});

client.login("YOUR-DISCORD-TOKEN");
  1. Save and close the index.js file.
  2. Open Google Play.
  3. Search for Termux.
  4. Find and install Termux.
  5. Once Termux has been installed on your device, open it.
  6. Enter the following command apt upgrade then execute it.
  7. Enter the following command y then execute it.
  8. Enter the following command apt install coreutils then execute it.
  9. Enter the following command apt install nodejs then execute it.
  10. Enter the following command y then execute it.
  11. Enter the following command termux-setup-storage then execute it and allow the storage permission.
  12. Enter the following command npm install -g nodemon then execute it.
  13. Enter the following command cd /storage/emulated/0/DiscordBOT then execute it.
  14. Enter the following command node index.js then execute it.
  15. If you did everything correctly, message index.js has been executed should appear.
  16. If you provided the correct token, message bot has logged into the account should appear.

FAQ

How do I start the bot?
You can start the bot by doing the two commands, first command will be cd /storage/emulated/0/DiscordBOT, then second command will be node index.js, that’s it.

How do I stop the bot?
You can stop the bot, by tapping and holding your finger on the screen to get the more popup, which then you will click it and then press kill process, or you can just press ctrl-c shortcut to stop it.

How do I update the bot?
You can update your bot, by creating a shutdown command for your bot, once you will have it, run the bot command and go to Termux and then enter the following command node index.js.

How long my bot will run for?
The bot will run 24/7 unless your device runs out of the battery or once you lose the internet connection.

How much RAM, MEMORY, and CPU my bot will have?
This all depends on your device and internet. The better device is, the better your bot hosting is.

:warning: WARNING :warning:

Do NOT share your bot token, as it will allow anyone to access your bot.

If you have any questions, feel free to ask one :slightly_smiling_face:

13 Likes

I don’t have android, so i can’t do it =(

1 Like

You can always use your computer or a raspberry pi

4 Likes

installs android on raspberry pi to do the tutorial
I’ve done it and it’s not that bad

4 Likes

Yeah, I am hosting my bot 24/7 on it, I didn’t have to pay a single penny for it :joy:

2 Likes

Besides the internet, phone bill.

2 Likes

Most isps provide unlimited bandwidth.

2 Likes

You still have to pay for the phone. Ain’t nothing in the world is free.

1 Like

image
You should place the message event outside of the ready scope, nesting events is a horrible idea and can cause unexpected behaviour, for example ready event being emitted twice for some reason will make the bot respond twice to any commands.

1 Like

Thanks! I fixed it…

2 Likes

Yeah but most of us, has a phone (with unlimited data), so there is no additional costs for hosting the bot.

This is so helpful! I’m trying it now!

2 Likes

Glitch should get some self-hosted servers for people who make bandwith intensive servers with a good ISP

What do you mean?

like they also have physical access to the servers and get to customize like everything. Basically they buy the hardware themselves

2 Likes

I started to self-host on my phone a few days ago. But theres a lot of latency delays (when the phone is sleeping), and a lot of reconnections.

I turned off battery optimization to keep termux running in the background even the app is not in the app switcher.

1 Like

This method likely isn’t practical, it may just be more of a proof of concept.

1 Like

(Reply to @Nicsena). Somehow I don’t have that problem, my phone is sleeping for almost 12 hours each day, and the bot as no visible delay, and it works 24/7, and I am happy cause I don’t have to pay additional money. Probably because something related to your device or your internet is making the trouble. I don’t really know, but for me it works perfectly. Hosting bot especially on one server shouldn’t be a trouble.

1 Like

If you’re rooted you could probably go way beyond and completely prevent the OS from killing it for whatever reason and start the bot instantly on device restart.