Discord has Bot Development Library for Many Languages and a library for python [discord.py](https:: //pypi.org/project/discord.py/).
Use discord.py to create a bot that can be used when recruiting online game quests and matchmaking opponents, and actually use it for about a month. I've seen it, so I'll write it as an article.
Click here for the code rather than the theory. https://github.com/coleyon/discord-partypoll
Roughly speaking, it is a bot that consists of the following two functions.
PartyPoll
-Similar to SimplePoll, a function that allows you to publicize the event and recruit participants.Cron
--PartyPoll command to the bot itself, cron Scheduling and scheduled execution with a similar setting format Function to makeBot as a Python program is configured to run on a Docker container.
For example, set up ʻUbuntu 18.04 LTS x86-64` on EC2. The free tier is sufficient.
Install docker and compose.
I think it looks like this.
$ docker --version
Docker version 19.03.12, build 48a66213fe
$ docker-compose --version
docker-compose version 1.27.2, build 18f557f9
$ id
uid=1000(ubuntu) gid=1000(ubuntu),
#Omission...
,999(docker)
$
$ git clone https://github.com/coleyon/discord-partypoll.git
Cloning into 'discord-partypoll'...
...
Resolving deltas: 100% (136/136), done.
$ cd discord-partypoll/
$ docker-compose build
$ docker images | grep partypoll
discord-partypoll_discord-bot latest ...
$
Create an application on the Developer Portal (https://discord.com/developers/applications).
Get the Client Secret
from the app's General Information
menu and set it to DISCORD_BOT_TOKEN
in docker-compose.yml
.
version: "3"
services:
discord-bot:
restart: always
build: .
environment:
DISCORD_BOT_TOKEN: "yourtoken"
Get the OAuth2 URL where Scopes is BOT from the ʻOAuth2menu of the app. For Permissions, give
Send Messages,
Manage Messages, ʻAttach Files
, Mention Everyone
, ʻAdd Reactions`.
Access the OAuth2 URL in your browser and invite the bot to the Discord server.
Generate requirements.yml
from Pipfile
.
$ pipenv lock -r > requirements.txt
Start the Bot program (Docker container as the execution environment).
$ docker-compose up -d
$ docker-compose logs -f
Attaching to discord-partypoll_discord-bot_1
discord-bot_1 | -----Logged in info-----
discord-bot_1 | {BOT_NAME}
discord-bot_1 | {BOT_ID}
discord-bot_1 | {DISCORDPY_VERSION}
discord-bot_1 | ------------------------
discord-bot_1 | Poll Extension Enabled.
discord-bot_1 | Cron Extension Enabled.
^CERROR: Aborting.
$
Launching the Bot program brings the bot on Discord online and ready for use.
This command is for recruiting parties with a maximum of 20 people in total for the entire team. / ppoll total 20 people 3 teams 20 TeamA TeamB TeamC
This command is for recruiting parties for up to 4 people in total for each team. / ppoll each 4 people 3 teams [4] TeamA [4] TeamB [4] TeamC
See the / ppoll help
command description or the Git repository readme.md for more information.
You can set the execution timezone. The default is Japan time (Asia / Tokyo), but you can set it to something like Eastern Time (EST).
/cron enable
It will be like this. See the / cron help
command description or the Git repository readme.md for more information.
Basically, Official Docs is the bible, but the members of the online game introduced the following books during the making.
When I read it, it was very easy to understand and it was useful because there were many contents that I could not grasp in the official manual, so it is recommended for those who are interested in making Discord bots.
Recommended Posts