For those who "want to make a Discord Bot but do not have a PC", I will introduce how to make a Discord Bot with one Android device and actually operate it. The explanation is for beginners as much as possible, but detailed explanations such as Python, discord.py, Linux commands, Vim commands, etc. are omitted.
Termux can be installed from the Google Play store. https://play.google.com/store/apps/details?id=com.termux
Termux is an emulator that does not require rooting and can prepare a Linux environment. Here's how to write a Discord Bot using Python and Vim.
First, execute the following command in the terminal to update apt and install Python and Vim. ($ Indicates that it is a command line and no input is required)
$ apt update
$ apt upgrade
$ apt install python
$ apt install vim
Next, install a library called discord.py that allows you to easily run DiscordBot in Python.
$ pip install discord.py
pip install yarl
.Create a directory to put the Python file to be executed next and move it.
$ mkdir {Favorite directory name}
$ cd {Directory name created above}
$ vim {Favorite file name}.py
The above command will open Vim for a new file, so type ʻi` on your keyboard to enter INSERT mode. Copy the code below here. (I borrowed some of the ones on the site below)
import discord
client = discord.Client()
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
@client.event
async def on_message(message):
#I don't want to react if the sender is a bot
if message.author.bot:
return
#Find out if it starts with "Good morning"
if message.content.startswith("Good morning"):
#Write a message
m = "Good morning" + message.author.name + "San!"
#Send a message to the channel to which the message was sent
await message.channel.send(m)
client.run("token")
Open the site of "https://qiita.com/PinappleHunter/items/af4ccdbb04727437477f" with a browser such as Chrome, and follow the section "Getting a token for bot" to create a bot account and use it on the server you want to use. Add a bot. Make a copy of the token that says "I'll use it later" here.
Open Termux, paste the token you copied earlier into the token part of cliant.run ("token ")
, save the file with ʻESC→
: wq`, and close Vim.
Run the Python file with the command below.
$ python {File name created earlier}.py
If you see Logged in as ...
, your bot is working.
Try sending a good morning
etc. on the server where you added the bot and see if you get a response.
If you want to quit, quit Termux and the bot will not work either. If you want to keep your bot running all the time, you can use Heroku.
By the way, Git can also be used with Termux, so it is possible to deploy to Heroku only on Android.
How to make a simple Discord Bot with Python Run Discord bot on Android device (Termux) Create a Linux environment using Termux on Android without rooting!
Recommended Posts