Launch the Discord Python bot for 24 hours.

what is necessary

-Repl.it account

That's all you need.

Step 1

Click "+ new repl".

0.png

Step 2

Create a new repl.

1.png

Step 3

Create "main.py".

2.png

#You need this at first.
import os
import keep_alive

# client.You need this before the run.
keep_alive.keep_alive()

#And client.run looks like this.
client.run(os.getenv('TOKEN'))
import discord
import os
import keep_alive

#Generate the objects needed for the connection
client = discord.Client()

#Processing that operates when receiving a message
@client.event
async def on_message(message):   
    if message.content == 'Secretary Jiàng':
        await message.channel.send('Nyan')
        await message.add_reaction('⭕')


#Launching a bot and connecting to a Discord server
keep_alive.keep_alive()
client.run(os.getenv('TOKEN'))

Step 4

Create "help.txt".

2.png

discord.py
flask

Step 5

Create "keep_alive.py".

3.png

from flask import Flask
from threading import Thread

app = Flask('')

@app.route('/')
def main():
	return 'Bot is aLive!'

def run():
    app.run(host="0.0.0.0", port=8080)

def keep_alive():
    server = Thread(target=run)
    server.start()

Step 6

Create ".env".

2.png

TOKEN = XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Step 7

Finally, click "run".

Other

"poetry.lock" and "pyproject.toml" are automatically generated.

5.png

Recommended Posts

Launch the Discord Python bot for 24 hours.
Python beginner launches Discord Bot
Create a Twitter BOT with the GoogleAppEngine SDK for Python
See python for the first time
What is the python underscore (_) for?
Command for the current directory Python
Discord Bot with recording function starting with Python: (5) Directly operate the Discord API
python launch
MongoDB for the first time in Python
Launch the Python interpreter from Git bash
Pandas of the beginner, by the beginner, for the beginner [Python]
2016-10-30 else for Python3> for:
python [for myself]
The fastest way for beginners to master Python
How to specify the launch browser for JupyterLab 3.0.0
Discord bot with python raspberry pi zero with [Notes]
[Python] I tried substituting the function name for the function name
Created a Python wrapper for the Qiita API
vprof --I tried using the profiler for Python
[Python] matplotlib: Format the diagram for your dissertation
Create a LINE BOT with Minette for Python
Wagtail is the best CMS for Python! (Perhaps)
Upgrade the Azure Machine Learning SDK for Python
Use logger with Python for the time being
Discord in Python
I tried python programming for the first time.
Tips for hitting the ATND API in Python
Python: Prepare a serializer for the class instance:
[Python] I searched for the longest Pokemon Shiritori
Image processing? The story of starting Python for
[Python] Predict the appropriate rent for an apartment
Code for checking the operation of Python Matplotlib
Call Polly from the AWS SDK for Python
What I got into Python for the first time
I tried Python on Mac for the first time.
Discord Bot with recording function starting with Python: (3) Cooperation with Database
Discord Bot with recording function starting with Python: (1) Introduction discord.py
HoloViews may become the standard for Python visualization tools
Make a BOT that shortens the URL of Discord
Information for controlling the motor with Python on RaspberryPi
Electron is the best solution for Python multi-platform development
Python program that looks for the same file name
[For play] Let's make Yubaba a LINE Bot (Python)
[For beginners] Learn basic Python grammar for free in 5 hours!
python memo (for myself): About the development environment virtualenv
How to operate Discord API with Python (bot registration)
About Python for loops
Find the maximum Python
Discord bot memorandum ① bot creation
the zen of Python
About Python, for ~ (range)
python textbook for beginners
Refactoring tools for Python
python for android Toolchain
[Python] Split the date
OpenCV for Python beginners
Install Python (for Windows)
[Python] for statement error
Python environment for projects
I touched the latest automatic test tool "Playwright for Python"
Enable the virtualenv Python virtual environment for Visual Studio Code