Skip to main content

Discord.py Bot Template

This page provides a starter template for building and hosting Discord.py bots on Cytric.nl. You can use this template to quickly set up your bot and deploy it to GitHub and Cytric.

Features

  • Python 3.8+
  • Discord.py library
  • Ready for deployment to Cytric
  • Example GitHub Actions workflow

Example Bot Code

import discord
from discord.ext import commands
import os

intents = discord.Intents.default()
bot = commands.Bot(command_prefix="!", intents=intents)

@bot.event
async def on_ready():
    print(f"Logged in as {bot.user}")

@bot.command()
async def ping(ctx):
    await ctx.send("Pong!")

bot.run(os.getenv("DISCORD_TOKEN"))

Deploy to GitHub

Use our official template: Cytric-Bot-Template-PY
  1. Fork or clone the template repository.
  2. Add your bot token as a GitHub secret named DISCORD_TOKEN.
  3. Push your code changes to GitHub.

Example GitHub Actions Workflow

Create .github/workflows/deploy.yml:
name: Deploy Discord.py Bot
on:
  push:
    branches: [main]
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: "3.8"
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install discord.py
      - name: Run bot
        env:
          DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }}
        run: |
          python bot.py

Resources