📎 Webclip
Create a Discord Bot in Python
The page walks through creating a Discord bot in Python, first as a simple bot that replies to hello and goodbye, then as a Minecraft bot with !mc subcommands for help, server usage, server status, and who is online. It also covers creating the Discord application, adding the bot through OAuth2, and storing the token in a .env file.
Reading notes#
- The tutorial uses a Python virtual environment and installs
discordandpython-dotenv. - It says to create a Discord application, add a bot, and authorize it to a server through an OAuth2 URL.
- The basic bot loads
DISCORD_TOKENfrom.env, listens for messages, and replies with the sender name when the content ishelloorgoodbye. - The Minecraft bot uses
commands.Bot(command_prefix="!")and amccommand with an argument. !mc helpsends a usage message.!mc serverusagegets the system load withmultiprocessing.cpu_count()andos.getloadavg().!mc serverstatusrequestshttps://api.mcsrvstat.us/2/{minecraft_server_url}and reports whether the server is online.!mc whoisonlinerequests player data from the same API and formats the number of online players and their names.- The page says the bot source code is in a GitHub repository.
