Sample Discord bot, using Python, to access the Clash of Clans API
- Install the latest version of Python.
- Sign up for a Clash of Clans Developer Account.
- Sign up for a Discord Developer Account and create an App with a Bot User.
- Rename creds_sample.pytocreds.pyand add your Clash of Clans Account email and password, and your Discord Bot Token.
- Create and activate a virtual environment python3 -m venv venv_bot && source venv_bot/bin/activate
- Run pip install -r requirements.txtto install dependencies like the discord.py & coc.py libraries.
- Run python bot.py
- Add your bot to a test Discord Server using an URL like this:
https://discordapp.com/oauth2/authorize?client_id=Insert Client ID from your Discord App&scope=bot
- Send the command !clan #CLASH_CLAN_TAGto load info about the clan.
New developers may not see the benefit of using a virtual environment until they start making a second or third bot. They may come to realize that updating their packages for one bot will interfere with the other bots and potentially even breaking their other bots. This is because you are downloading and updating your packages globally. A way around this is using virtual environments to segregate projects.
python3 -m venv venv_test
source venv_test/bin/activate
You should now see your environment tag in the command line indicating that you are now in the virtual environment.

TubaKid, Sidekick, mathsman, majordoobie...
Find us and ask questions at https://discord.gg/Eaja7gJ