Create Discord Bot with Python in Android 1

Create Discord Bot with Python in Android

If you wanted to create discord.py bot in android. You can read this psot, after reading this you can finally make the python bot.

APK NEEDED FOR BOT

1. Pydroid 3 (You can found this is playstore)

2. Pydroid repository plugin (You can found this is on playstore)

STEP 1

Open pydroid 3, Then go to pip by sliding your finger left.

Create Discord Bot with Python in Android 2
click on pip
Create Discord Bot with Python in Android 3
go to install panel and type discord.py

STEP 2

Now come back where you start and paste this code.

import discord

class MyClient(discord.Client):
    async def on_ready(self):
        print('Logged in as')
        print(self.user.name)
        print(self.user.id)
        print('------')

    async def on_message(self, message):
        # we do not want the bot to reply to itself
        if message.author.id == self.user.id:
            return

        if message.content.startswith('!hello'):
            await message.channel.send('Hello {0.author.mention}'.format(message))

client = MyClient()
client.run('token')

STEP 3

Create Discord Bot with Python in Android 4
Now replace your bot token here.

STEP 4

Create Discord Bot with Python in Android 5
Save the file by clicking on folder icon

Choose your saving location then click on SELECT FOLDER while choosing location.

STEP 5

Create Discord Bot with Python in Android 6
Then name the file, ex – bot.py or newfile.py (In last .py is must)
Create Discord Bot with Python in Android 7
In last click on this play button and wait for 3 – 4 seconds then see your bot

Create Guess The Number Command

This is the command only for fun which will check that you guessed number right or wrong

PASTE THIS CODE

import discord
import random
import asyncio

class MyClient(discord.Client):
    async def on_ready(self):
        print('Logged in as')
        print(self.user.name)
        print(self.user.id)
        print('------')

    async def on_message(self, message):
        # we do not want the bot to reply to itself
        if message.author.id == self.user.id:
            return

        if message.content.startswith('$guess'):
            await message.channel.send('Guess a number between 1 and 10.')

            def is_correct(m):
                return m.author == message.author and m.content.isdigit()

            answer = random.randint(1, 10)

            try:
                guess = await self.wait_for('message', check=is_correct, timeout=5.0)
            except asyncio.TimeoutError:
                return await message.channel.send('Sorry, you took too long it was {}.'.format(answer))

            if int(guess.content) == answer:
                await message.channel.send('You are right!')
            else:
                await message.channel.send('Oops. It is actually {}.'.format(answer))

client = MyClient()
client.run('token')

After that replace your token in last, then save the command and run it.

EDIT IN COMMAND

In this command bot will edit his own message in given time.

import discord
import asyncio

class MyClient(discord.Client):
    async def on_ready(self):
        print('Connected!')
        print('Username: {0.name}\nID: {0.id}'.format(self.user))

    async def on_message(self, message):
        if message.content.startswith('!editme'):
            msg = await message.channel.send('10')
            await asyncio.sleep(3.0)
            await msg.edit(content='40')

client = MyClient()
client.run('token')

Conclusion

Hope you are on your way to make a perfect bot for your discord server. We are always here to help you. If you are facing some error please let us know in the comments below.

Leave a Reply

Your email address will not be published. Required fields are marked *