Developing and launching your own bot for Discord has long been considered the prerogative of the owners personal computers that require complex IDEs and a stable desktop environment. However, modern mobile devices have enough processing power to run scripts in languages โ€‹โ€‹like Python or JavaScriptwhich opens the door to creating automation directly from your phone. In this article, we will analyze in detail the process of registering an application in the Developer Portal, setting up rights and directly running the code through a terminal emulator.

You will learn what tools are needed to comfortably work with code on a smartphone screen and how to avoid typical beginner mistakes when working with API. Despite the apparent complexity, the whole process comes down to the sequential implementation of specific steps, which we will describe in as much detail as possible. Willingness to experiment and attentiveness to syntax is all that is required of you for success.

Registering an application in the Discord Developer Portal

The first and mandatory step is to create an entry for your future bot in the official developer portal. To do this, you need to go to the Discord Developer Portal website through any mobile browser, preferably in the full version of the site, and log in with your main account. It is this account that will act as the owner of the bot, so make sure that it is securely protected.

After logging in, click the button New Application in the upper right corner of the screen and enter the desired name for your project. This name will be displayed in the list of server users, so it is better to immediately select something recognizable and corresponding to the functionality. In the menu that opens on the left, select the tab Bot and click the button Add Bot, confirming the action.

At this stage, you will be provided with a unique access token, which is the key to managing the bot. Never give this token to strangers or publish it publicly, since the owner of the token receives full control over the bot. Copy it by clicking the button Copyand save it in a safe place, for example, in notes, since it will no longer be possible to see it again.

โš ๏ธ Attention: Discord Developer Portal interface is updated periodically, and button layouts or tab names may change slightly. If you do not find the described option, carefully examine the adjacent menus or check the current documentation on the site.
What to do if the token has leaked?

If you accidentally published a token or suspect a leak, immediately click the Regenerate button in the Bot section on the developer portal. The old token will no longer work and you will need to update it in your bot's code.

Setting permissions and adding a bot to the server

Before the bot can perform any actions, it must be given the appropriate permissions. In the section Bot find the subsection Privileged Gateway Intents and activate the switches Message Content Intent, Server Members Intent and Presence Intent depending on the tasks of your script. Without enabling these options, the bot may not see the contents of messages or the status of users.

To add a bot to a specific server, go to the section OAuth2 -> URL Generator. In the scopes table, check the box opposite bot, and in the list that appears below Bot Permissions select the necessary rights, for example, Send Messages, Embed Links or Manage Channels. The generated link at the bottom of the page will allow you to add a bot to any server where you have administrator rights.

  • ๐Ÿ”‘ Administrator โ€” gives full rights, it is recommended to use only for test servers.
  • ๐Ÿ’ฌ Send Messages โ€” basic right for sending text replies.
  • ๐Ÿ”— Embed Links โ€” allows you to format messages in beautiful blocks.
  • ๐Ÿ“ Attach Files โ€”necessary if the bot must send images or files.

After following the link, select a server from the list and confirm authorization. Now the bot is on the server, but it is offline since we have not yet run the executable code that will connect to the Discord servers. Make sure that the bot has a role in the server settings that allows it to read and write in the required channels.

โ˜‘๏ธ Checking the bot settings

Done: 0 / 1

Selecting and installing a development environment on Android

To write and run code on Android, you will need a specialized editor application. One of the most popular and powerful environments is Termux, which emulates a Linux terminal, but for beginners, Pydroid 3 or Acodemay be a more convenient option. The choice depends on your skill level: Termux gives more freedom, but requires working with the command line.

If you choose Pydroid 3, simply download the application from the Google Play Store or F-Droid. After installation, open the application and wait for the initial environment setup. In the menu Pip you will need to install the library discord.py, which is the main tool for interacting with the Discord API in Python.

When working with Termux, the installation process looks different: after launching the application, enter the command pkg update && pkg upgrade to update the packages. Then install Python with the command pkg install python and the necessary dependencies, such as git for cloning repositories or nano for editing files directly in the terminal.

๐Ÿ’ก

Use an external keyboard or connect a Bluetooth keyboard to your smartphone. Typing code on the virtual on-screen keyboard is extremely inconvenient and increases the risk of syntax errors.

Writing bot code in Python

Create a new file with the extension .py, for example, bot.py, and start by importing the necessary libraries. The basic template includes creating a client, handling an event that signals a successful connection, and an echo function to respond to user messages. data-i="94">await message.channel.send('Hi! I'm working.') on_ready, which signals a successful connection, and an echo function to respond to user messages.

import discord

from discord.ext import commands

intents = discord.Intents.default()

intents.message_content = True

client = discord.Client(intents=intents)

@client.event

async def on_ready():

print(f'{client.user} connected successfully!')

@client.event

async def on_message(message):

if message.author == client.user:

return

if message.content.startswith('!hello'):

await message.channel.send('Hi! I'm working.')

client.run('YOUR_TOKEN')

Pay attention to the line intents.message_content = True โ€”it is critical for modern versions of the library, otherwise the bot will not be able to โ€œseeโ€ the text of messages. In the function on_message we added a check so that the bot does not respond to itself, and a condition for reacting to the command !hello.

Instead of hard coding the token in the code, which is unsafe, professionals recommend using environment variables or separate configuration files that do not end up in the repository. However, for the first launch and testing on the phone, directly entering the token into the function argument run is an acceptable simplification.

  • ๐Ÿ“ Importing libraries - connecting the discord and commands modules.
  • ๐Ÿ”Œ Creating a client โ€”initializing the connection taking into account access rights.
  • ๐ŸŽฏ Event processing โ€”decorator functions for reacting to actions.
  • ๐Ÿš€ Running a loop โ€”the run method, which blocks execution and waits for events.

Running and debugging a script

After writing the code, press the run button (usually a blue circle with a triangle in Pydroid or a command python bot.py in Termux). If everything is done correctly, you will see a message about successful login in the console, and in the Discord application the bot's status will change from offline to online (green circle).

Try to write !hello in the text channel where the bot was added. If he responds, then the connection with the Discord servers is established correctly. If errors occur, carefully read the "traceback" (list of errors) in the emulator console - the line of code where the failure occurred is usually indicated there.

โš ๏ธ Attention: Mobile operating systems aggressively save battery power and can โ€œkillโ€ the Python process in the background. For the bot to work continuously, the phone screen must be lit, or you need to disable battery optimization for the selected code editor.
๐Ÿ’ก

If the bot only works when the application is open, this is normal for mobile hosting. For 24/7 operation, consider cloud server options.

Problems with network and stability

mobile data (3G/4G/5G) is less stable than a wired connection and can lead to connection interruptions (Error 402 or Connection Reset). The library discord.py has built-in reconnection mechanisms, but if the IP address changes frequently (for example, when switching between Wi-Fi and a mobile network), the session may be reset.

To minimize problems, try to use a stable Wi-Fi connection during development and testing. It is also worth considering that some mobile operators may block certain ports or protocols used for the WebSocket connection, which is necessary for the bot to work in real time.

If you encounter an error Privileged intents are not enabled, return to the Discord Developer Portal and make sure that you have not only enabled the necessary intents, but also saved the changes with the button Save Changes. Applying settings on the Discord server side can take from a few seconds to a couple of minutes.

Comparison of launch methods on Android

There are several approaches to running code on a mobile device, and each has its own advantages and disadvantages. Below is a table to help you choose the optimal tool for your purposes.

Method Complexity Functional Stability
Pydroid 3 Low High (GUI, Pip) Medium (depending on OS)
Termux High Maximum (Linux) High
Replit (Web) Low Medium (cloud) High (does not depend on the phone)
Acode + Termux Medium High High

For beginners who are just learning how to create bots, a bundle Pydroid 3 or web editor Replit will be the most gentle. Termux is recommended for those who are already familiar with the Linux command line and want to gain maximum control over the execution process.

Switching to permanent hosting

Keeping the phone turned on around the clock for the bot to work is ineffective and harmful to the deviceโ€™s battery. When your project grows beyond the experimental stage, consider moving your code to a virtual server (VPS) or using free cloud platforms.

The code you write on your phone is fully compatible with server operating systems. All you need to do is download the file bot.py and the dependency file requirements.txt to the remote machine. This will free up your smartphone and provide the bot with stable uptime and a fast Internet channel.

๐Ÿ“Š Where do you plan to run the bot?
On the phone 24/7: On a cloud server: For tests only: I donโ€™t know, you need to think about:

Frequently asked questions (FAQ)

Is it possible to create a bot without programming knowledge?

Yes, there are bot designers (for example, YAGPDB or MEE6) that allow you to configure functionality through the web interface without writing code. However, to create unique logic and complete control, knowledge of Python or JavaScript is required.

Will the bot work if I turn off the phone?

No, if the bot is running locally on your device via Pydroid or Termux, it will stop working immediately after turning off the phone or closing the application. To work 24/7, you need an external server.

Is it safe to store a token in a file on the phone?

It is relatively safe if the phone is password protected and there are no viruses on it. However, it is better to use environment variables or services like dotenvto avoid hardcoding sensitive data directly into the script.

Which language is better to choose to start with: Python or JavaScript?

For Discord bots Python (discord.py library) is considered more friendly for beginners thanks to its readable syntax. JavaScript (discord.js library) is more powerful in asynchrony, but has a steeper learning curve.