This is a Discord bot for hosting Werewolf game (Ma Sói, Thỏ và Sói). This bot is created and contributed by DNH members
The game will automatically run without a human hoster. More fun!
Original making for Vietnamese player but able to port to any language.
Require python >= 3.9 Please note that this repo use Python 3.9 features, so it cannot run on python3.7
Install dependency packages:
python3.9 -m pip install -r requirements.txt
It's also possible to use pyenv
if you want to install this independently.
cp .env.example .env
Change the fill in the Mandatory fields:
# Mandatory fields
BOT_PREFIX=! =====> For use command in game like `!join` `!vote`
BOT_NAME=EXAMPLE_BOT =====> Your bot name, not important
GAME_CATEGORY=GAME =====> The bot will create a new Category channel in your discord server
DISCORD_TOKEN=ODgx**********************.YSsNGw.ya5O**********************. ===> Replace this by your own Bot token, generated in https://discord.com/developers/applications/<your_bot_id>/oauth2/general
DISCORD_DEPLOY_SERVER_ID=881************** ====> right click on your Discord server and copy the server id.
Right Click to copy ServerID:
Follow guide to create a new Discord bot and how to add it into your Discord server: https://discordpy.readthedocs.io/en/stable/discord.html
Note: You may need Priviledged Gateway Intents permissions to get the bot work properly due to Discord bug
You need to set bot's permission to allow it to create channel and run game.
In OAuth2 tab, choose bot in Scopes, then choose Adminstrator permission.
Simply run:
python3.9 bot.py
The bot should connect to your Discord server and online:
You MUST create these Admin
role and Members
role to play the game.
f_
. Eg: f_join
, f_create
, f_delete
.
You can see list of available commands in label or label. Note that you do not need to provide Admin and Members any permission. The bot will provide proper permission for them under GAME_CATEGORY.
Follow this guide to create and assign roles: https://www.howtogeek.com/809671/how-to-add-assign-roles-discord/
Assign you as Admin
role.
Then run this command:
!fcreate @bot_name
where @bot_name tag your bot display name in your server
if your bot can read the message, then it will automatically create a new category channel like:
If you want to be a normal player, you can safely remove your Admin role now and enjoy the game.
!version
!help
!help cmd vote
!help role cupid
English version: TODO
You can custom langauge under ./json directory.
User can join game via !join
command or !f_join
by Admin:
Then players vote to start game via !start
command.
After if the votes are greater than half of players, the game will be started:
Each player will have a personal channel, where they can cast spell or sleep :D
Players can discuss, !vote
for werewolf.
Player who is killed by werewolf/witch or is voted to die will be sent to cemetery channel:
But don't worry, you have chance to reborn :D (witch,zombie roles)
The game includes 2 phases every game day time:
The game will be ended if all werewolves are eliminated (villager win) or number of werewolves greater or equal number of villagers (werewolves win).
Leaderboard saves endgame result every game.
Enjoy!
python3 test.py
Sample successful output:
successfully loaded json/command_info.json
successfully loaded json/text_template.json
successfully loaded json/role_info.json
reset_game_state
# Code standard
We apply Autopep8 for this project.
Please run `./format.sh` before creating new PR.
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
====== Begin test case at testcases/case-witch-reborn-wolf.json =====
...
<Many lines hidden here>
...
reset_game_state
#lobby: Trò chơi đã kết thúc.
gameplay created!
====== End test case =====
FINISH ALL TEST CASES SUCCESSFULLY
Tips: you can reduce the TEST_THREAD_DELAY_TIME for faster run
As usual, free deployment services have certain limitations, typically after a period of inactivity, your bot may go to sleep and all data will be lost.
To address this issue, please follow these steps:
web/requirements.txt
keep_alive()
function in bot.py
. Now we have our website running together.Explanation: Your bot will be alive because the monitoring services request(ping) every 5-10 minutes and keeps our website running up.
Alternatives: Some deployment services may block request from UptimeRobot, please consider others website: https://www.fastcron.com/ https://cron-job.org/en/ https://uptime.com/ https://uptime-monitor.io/
Currently, data can be stored in local json files or in Github Gist files To use the Gist, please follow these steps:
Create a personal access token Recommended: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-fine-grained-personal-access- token Or: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token-classic
Create a personal Gist (private or public) with the same filename as the local json, please be aware that a gist can include multiple files
Important note: Gist file and local json file must have the same name to ensure synchronization
GITHUB_GIST_TOKEN
and GITHUB_GIST_ID_URL
to the .env
file. Please see .env.example for more details. If Gist is not used, you MUST NOT include those variablesA library bug while adding member to gameplay
channel if using discord.py==2.2.2
Prefer to use discord.py==1.7.3
It's open source and free to use Discord bot.
Don't hesitate to contact us for guiding setup. Discord chat group: https://discord.gg/ceJAgPEMCw