STR Coding Club logo STR Coding ClubLearn to code, together
Club Projects

Build a Club Discord Bot as a Python Group Project

Our club ran a Discord bot as a group project for the first time two years ago, and the first version lived on one student's laptop.

A chat channel showing a bot replying to a session schedule command beside a laptop with Python code

Our club ran a Discord bot as a group project for the first time two years ago, and the first version lived on one student's laptop. It answered the schedule command for eleven days, then he went on holiday, closed the lid, and the bot died in front of forty people in the middle of a session. Nobody else had the code. Nobody had the token. The project was finished, in the wrong sense of the word.

We have run it three times since and it is now the project I recommend over any other for a mixed ability group, because a bot splits into genuinely separate jobs in a way a calculator or a text adventure never does. One person can write a single command and ship something the whole club uses that evening. The parts that go wrong are organisational rather than technical, which is useful, because those are the parts beginners learn least often.

Why a bot suits a mixed group

A command is a small, closed unit of work. One function, one input, one reply. A member who learned functions last month can write a dice roller or a coin flip in twenty minutes and see it answer a real person in a real channel, which is a different feeling from printing to a terminal nobody else sees.

At the same time the project has room above that. Someone has to store data so the bot remembers things between restarts. Someone has to handle the case where a user types nonsense. Someone has to work out why the bot replies twice. Those jobs stretch the strongest members without blocking anybody else, and they happen in the same codebase, which is what makes it feel like one project rather than nine homework assignments.

The library to use is discord.py, installed into a virtual environment with pip. Create the application and the bot user in the developer portal, invite it to a private practice server rather than your main club server, and switch on the message content intent if your commands read ordinary messages. That intent is the single most common reason a first bot appears online and then ignores everything said to it.

Splitting the work so nobody waits

We run it over five sessions of ninety minutes with eight to fourteen people. The split that works is by command, not by layer, and the reason is that layers create queues. If one person owns storage and three people need storage, those three spend a week doing nothing.

  1. Session one: everyone sets up the same environment, runs the same skeleton bot, and confirms it replies ping to a test command. Nobody writes anything new.
  2. Session two: each member picks one command from a list on the whiteboard and writes it in their own file. Dice, coin flip, countdown to the next session, random challenge from a list, a joke, a timer.
  3. Session three: two mentors merge the files into cogs, one module per command group, and the group walks through the merge together so they see why files were kept separate.
  4. Session four: the stretch jobs land. Saving data to a JSON file, a help command built from the registered commands, input validation, and a cooldown so one person cannot spam the dice roll.
  5. Session five: deploy somewhere that is not a laptop, write the README, and demo it live in the main server.

Keep the command list on the board visible and let people claim with their initials. Two members claiming the same command happened once, and the resulting pair worked better than either would have alone, so I stopped trying to prevent it. Breaking the work into claimable pieces is the same muscle as learning to break a coding problem into small steps, and a group project is where that habit becomes visible to everyone.

The one rule I enforce is that every command must do something a member of the club actually wants. A command that reports the next session time gets used. A command that returns a random number between one and a million does not, and the difference in how hard people work on them is remarkable.

The advice I now ignore

Most tutorials open with slash commands, because they are the modern interface and because Discord pushes them. I have taught it both ways and I now start beginners on prefix commands, the kind triggered by a character like an exclamation mark at the start of a message.

The reason is feedback speed. Slash commands have to be registered with Discord, and that registration can take a few minutes to appear, sometimes longer on a global sync. A beginner who changes a word, restarts the bot, and sees no change has no way to tell whether the code is wrong or the sync is slow. That ambiguity is poison in a first project. Prefix commands update the instant the bot restarts, so the loop between editing and seeing the result stays under ten seconds, which is where learning happens.

We move to slash commands in session four, once members trust that their code does what they think. By then they can read a sync delay for what it is instead of assuming they broke something.

The second piece of common advice I would push back on is to put the bot token in a config file and gitignore it. Correct, and incomplete. In three years I have had two tokens leaked by members, both through screenshots posted for help rather than through commits. Teach the token as a password from the first minute, load it from an environment variable, and tell everyone that a leaked token means regenerating it and nothing worse, so they report it instead of hiding it.

The things that actually break

The bot replies twice. Almost always two copies running, one on somebody's laptop and one on the host. Give each environment a different status message so you can see at a glance which instance answered.

The bot goes offline every night. Free hosting tiers sleep, and a bot that sleeps is a bot that is not there when someone asks it something. A small always on instance costs around 5 a month, and a club can run one for everybody. Running it on a spare single board computer in the room works too and teaches more, with the catch that somebody has to care about it over the summer.

Data vanishes on restart. Anything held in a Python dictionary disappears when the process stops, which surprises people every single time. Writing to a JSON file after each change is the right first answer at this level, and it is a natural place to connect the project to file handling practice that otherwise feels abstract.

Everyone edits the same file. This is the merge conflict lesson, and a bot project delivers it gently because the conflicts are small. If your club has not used version control yet, the project is a good reason to start, and the walkthrough for a Git group project covers the workflow we use.

One honest caveat about scope. I would not attempt this with a group where more than about a third of members have never written a function, because the setup session alone will eat two meetings and the energy drains. For that group a six week project with a narrower technical floor works better, and the six week project plan sets out how to pick one.

FAQ

How many members can work on one bot?

Up to about fourteen in our experience, with two mentors. Past that the command list stops being things anyone wants and starts being filler, and the merge sessions run long. With a larger club, split into two bots on two practice servers and let them demo against each other.

Do members need their own Discord developer account?

For the setup session, yes, and it is worth the twenty minutes. Each person creates their own test bot and invites it to their own private server, so they can restart and break things without affecting anyone. The shared club bot comes later and lives under one account a mentor controls.

What should the bot do first?

Reply to one command with one fixed line of text. Resist any feature until that works for every member on their own machine. The first real command we add is the one that reports when the next session is, because the whole club notices if it is wrong.

Is Python the right choice for a club bot?

If your club already teaches Python, yes, and discord.py maps cleanly onto decorators and async functions that members will meet again later. JavaScript has a larger bot ecosystem, which matters for a club that teaches web work. Switching language for one project costs more than the ecosystem gains you.

IA
Imogen Achebe

Imogen started a coding club at her school and now trains volunteer mentors. She writes about first steps in coding and projects that work for groups of mixed ability.

More posts by Imogen

More in Club Projects

01doorganico 084goad 3hot8 4465456 after5internprogram ahandfulofblessings ahmadpc ahomcybersecurity allodialresources annodex antiquesandperiodcollectibles aotc asianworldkashmir beedlectrics bloggertemplatefree bluefeatheragency bodyweightsolution campaign08blog carfixadvisor catstreetcollective cbstvsports cnfanspurchasing committeeof500yearsofdignityandresistance covertopsdjs cs-kaiyuangame cuestacomunicaciontotal cxoutlet dancebetgame deskgearhub destinyvillastay detectmagazine di33 diamondsteelbuildings donmo dyanadropship emarsysfinance emimattl escapechan eskitarih evautoplay everythingweddings-orlando farmzone feedviewerapp foxstudiosscratch gamevui123 gleasongrade greetingsday hacklabasu haskell iw-kaiyun jagoanproperti jilidskripsi joltbusinessfinance juegodepokergratis juegospucca kaeru-festival latestmehndidesigns lestanzediottaviano litemagazines localcommunityhero lustrsazan mariashebets menswheels newwebstechs1 nikkit ootheday oxigenvpn plurfitness prefetial probudgetcarpetcleaning psychicmrsmartin pyaten qvantor rejoignezlogis rexzbot riselayouts ruchin rwxqsgd5 sakaltime shibiaowang shop-bot skrtips spotlesshaven tetapatrium topselller uneplanteartificielle vipertechcr webtech1223411 wo-kygaming yamaha-mekar yeknava yoybuysheets zenunwa yamaha-mekar jilidskripsi ankertoto ankertoto ankertoto