Skip to content

Discord bot template#

Use this template

A simple template for a Discord bot using discord.py, providing the essential tooling and basic building blocks for writing your own custom Discord bot in minutes, with minimal bells and whistles attached.

The template includes two "hello world"-style commands as a demonstration. Use these as a basis for adding new commands for your own special bot.

Further, the documentation (that you are reading right now!) serves as a guide for newcomers to understand all the inner workings of a Discord bot, some best-practice patterns to follow, and links to pertinent documentation on discord.py itself.

Happy botting!

Running the demo bot#

To start the demo bot:

  1. Clone the template repo;
  2. Follow the setup instructions, adding your own Discord bot token and Guild/Server ID; and
  3. Start the bot with uv run thebot (or just up as an alias).

When running and installed in your server, you get a simple bot that can respond to a Slash Command, /hello:

The test bot responding to /hello slash command

...and a prefix command, !whatsup:

The test bot responding to !whatsup command

After that, you can check out Anatomy of a Discord Bot for an in-depth explanation of how the bot works. Use this as a guide to making your own bot that can do whatever you want!

About this template#

This is a relatively simple Discord bot that responds to just two commands. It does not include other features that might make a bot more useful, such as any integrations with databases, APIs, etc. These are left as an exercise for the reader.

The template and this documentation are not affiliated with either Discord or the discord.py package. Please use the discord.py docs as a more complete reference for this package, and please direct any Discord-related issues to Discord support.

About the author#

👋 I'm GriceTurrble, a software developer who's been working with Python since 2014. I am occasionally active on Python Discord (or "PyDis", as some call it), where I offer advice and bad jokes to newcomers to the language and to programming in general.

I am no expert in Discord bots or the discord.py package in particular, but I love teaching folks new things. I wrote this template and its documentation from scratch, both to expand my own knowledge about it and, hopefully, to share those learnings with others.