Viewing entries tagged
raspberry pi

Python: Create a Discord Bot on Your Raspberry Pi Using

Python: Create a Discord Bot on Your Raspberry Pi Using

Create a Discord Bot on Your Raspberry Pi With Python and

This article will get you up and running with a Discord bot on your Raspberry Pi using the Discord.Py library.

The code has been updated to reflect Discord.Py’s re-write.
You can always view latest code, and more examples for this post, here:

This assumes that you've installed and are using Raspbian.

Table of Contents

Create app and invite bot to your server

If you already have a bot token, and a bot invited to your server, you can skip over to updating Raspbian.

1. Navigate to the Discord Developer Console

2. Click "New App"

3. Give it a name, and then click "Create App"

4. Click "Create a Bot User"

5. Keep note of the Token, as you'll need that later.

6. Invite the bot to your server

    a. Use the following URL to invite the bot to your server:
        (Replace your_client_id_goes_here with your bot's client ID)

7. You should now see the bot in your server (offline)

Update Raspbian

First you'll want to ensure your Raspbian installation is up to date. To do this, run the following commands:

1. Update package lists

sudo apt-get update

2. Upgrade packages

sudo apt-get upgrade

3. Clean things up

sudo apt-get dist-upgrade

4. Reboot your Pi!

Install Pre-Requisites for Python 3.7.x and Discord.Py


The latest version of Raspbian (10.x/Buster) ships with Python 3.7.x (which should work great with 

If you'd like to upgrade your OS to Buster, follow this article.

To check which version you have, run:

cat /etc/os-release

If you are running Buster (or Stretch), great! Click here to skip to the next step. Otherwise, continue below.

1. Install libssl-dev (to ensure we can use pip when we install the newest version of Python)

sudo apt-get install libssl-dev

2. Install libffi-dev (to ensure audio works with the Discord bot)

sudo apt-get install libffi-dev

3. Install libsqlite3-dev (this will be handy, as it installs libraries needed to install sqlite3 support)

sudo apt-get install libsqlite3-dev

Install Python 3.6.x

1. Grab the latest version of Python 3.x from


2. Extract the files, and enter the directory

tar xzvf Python-3.6.0.tgz
cd Python-3.6.0/

3. Run configure to check for dependencies, and get ready to build the Python installation
(This will take 2-5 minutes)


4. Run make to start compiling the software
(This will take 15-30 minutes)


5. Install Python 3.6.x
(This will take 10-15 minutes)

sudo make install

6. Reboot your Pi!

Install Discory.Py, and get a bot working

1. Install latest version of the Discord library for Python (Discord.Py)

sudo python3 -m pip install -U[voice]

2. Create a bot to test it out

    a. Create directory 

mkdir ~/pipy_bot

    b. Move to that directory

cd ~/pipy_bot

    c. Create an empty file


    d. Edit the file


    e. Copy/Paste the following content in the editor (be sure to change your_token_here to your bot's token):

import discord
from discord.ext import commands

TOKEN = ''

description = '''ninjaBot in Python'''
bot = commands.Bot(command_prefix='?', description=description)

async def on_ready():
    print('Logged in as')

async def hello(ctx):
    """Says world"""
    await ctx.send("world")

async def add(ctx, left : int, right : int):
    """Adds two numbers together."""
    await ctx.send(left + right)

    f. Save the file using CTRL+X, and "y"

    g. Run your bot!


Test Out Your Bot

1. Go to the Discord server where you've invited your bot to , and try issuing the ?help command

2. Once you verified that works, try the other ones as well!

Have a question or idea? Leave a comment below, or contact me here!

[Back to top]