How to create the Discord bot on the Raspberry Pi
Today, TipsMake.com will read with you how to do this on Raspberry Pi with Python.
Sign up for an account
If you do not have an account, here's how to sign up:
- Visit Discord.com and click Login , then select Register.
- Fill out the following form on the website:

- After logging in, directly create a new server.
- Then choose the name and icon.

You already have your account and server. Now you can move on to the next step. Don't forget to confirm your email address as it is a must for creating a bot.
Create an application
You need to declare a new application before creating the bot:
- Start by opening Discord's developer console by clicking here.
It looks like this:

- Create a new application by clicking the top right button
- Choose a name.
Your bot will get the application name. So, 'test' or 'myfirstapp' is probably not a good idea.
- To create the application, you need to confirm your email.
The application has been created, now you can create a new bot.

Create a bot
- Click Bot in the menu on the left.
- Then click Add bot and accept the confirmation message.
- A bot has been automatically created associated with your application.
Invite bot on server
The final step is to invite the bot to join your server:
- The first thing is to access this URL:
https://discord.com/api/oauth2/authorize?client_id=&scope=bot&permissions=1
Replaced with your client ID, you can find it on the application page.
- On the page that opens, select the server to join:

- Click Continue.
- Then click Authorization on the next screen.
The bot is already connected on the server. You can check it on your server:

The Discord section is now complete, you have everything you need to start working on your Raspberry Pi.
Code bot on Raspberry Pi
The goal here is to create a 'brain' for your bot. For now, it cannot do anything.
After a few prerequisites, the main part is to create a script that suits your needs.
Operating system
The example used the Raspberry Pi OS Lite to do this, but any system might be fine, because you only need Python.
As always, don't forget to update your system before going any further:
sudo apt update sudo apt upgrade
Prerequisite of Python
You need to install several Python packages:
sudo apt install python3-pip python3-cffi
PIP is the Python extension manager and CFFI is the interface between C and Python that the library uses.
Python 3 is required because the library does not work with earlier versions.
So it is python3-pip, not python-pip.
Basically, with this command, apt will install all other necessary packages.
Then update setuptools to make sure you have the latest version (if you have had PIP on your system before)
sudo pip3 install -U setuptools
Library
To keep things simple, you will use the library to interact with Discord
The article I chose is Discord.py from this GitHub repository because it is very easy to use.
To install it, simply copy this command:
sudo pip3 install discord.py
Basic script first
The article will start with a short example of how this library works, so you can check if everything in the configuration is good and move on to creating your projects.
When on Raspbian Lite, for example, use Nano as an editor, but you can use the option you like.
For example, on the Raspberry Pi OS Desktop, you can copy and paste code in Thorny or another editor.
Open your editor and create a new file:
nano MyFirstApp.py
Copy and paste these lines:
import discord from discord.ext import commands bot = commands.Bot(command_prefix='>') @bot.command() async def ping(ctx): await ctx.send('pong') bot.run('token')
Here is an example from the GitHub repository, see more here.
Basically, the goal is to answer pong when someone runs the ping command.
- The first two lines are here to import the necessary prerequisites from the library.
- Then, the prefix to detect a command ('>') is declared.
- The next block is to determine what order you are waiting for and what to do if you receive it. The syntax will be the same for each command you add later.
Finally, the example runs the bot with these parameters.
Here is the command to run the bot if you don't have an editor to do this:
python3 MyFirstApp.py
Change the name to match the one you created.
The code is fairly easy to read, and you don't need much else to do something interesting.
If you already have some basic knowledge in Python, you can add a few lines before the 'await' line and send a text variable instead of a static word (e.g. > ping => 40ms to monitor the Internet or another machine) such as.
You should read it
- 6 best bots to improve Discord server
- Is it safe to use Discord?
- How to add a bot to the Discord server
- How to Format Text as Code in Discord
- ChatGPT will come to Discord chat
- How to prevent Discord from hanging, freezing in Windows 10/11
- How to change Discord language into Vietnamese
- Steps to customize Discord interface
May be interested
- Steps to customize Discord interfacediscord has a variety of settings available that you can tweak to customize the look and feel, such as switching to a light theme, making messages more compact, adjusting color saturation, and more.
- How to add bot to Discord serveradding bots to your discord server helps automate moderation, create rating systems, play music, and many other useful features. the process is simple and widely used.
- How to fix Discord error does not openthe discord not opening issue has become one of the biggest problems for gamers who use this app as their main communication tool. this is a frustrating problem, but the fix is something that many people can easily do.
- How to create custom shortcut keys for Raspberry Piin windows, it's easy to use custom keystrokes to open your favorite apps, but in raspbian, the official operating system of the raspberry pi, the process is a bit more complicated.
- Ways to fix audio problems in Discordwhile it was originally built for discord, it has now evolved into a networking platform for all types of communities. whether it's for watching livestreams or playing voice games with others, audio is a key element of discord.
- 5 easy ways to know if someone has blocked you on Discordare you worried that a friend has blocked you on discord? even though discord doesn't tell you directly, there are easy ways to tell if someone has blocked you on discord. you can even see if you've been blocked without sending a direct message! this tipsmake article covers all the signs that you're blocked on discord, whether you're using a computer or the mobile app.
- Steps to permanently delete Discord accountdiscord is a great app that allows you to chat with your friends and meet like-minded people. but it's not for everyone. if you want to get out of discord, you'll wonder if it's possible to delete your discord account.
- How to add an ADC to Raspberry Pi: What you need to knowraspberry pi lacks analog input. this puts it at a disadvantage compared to microcontroller-based boards like the arduino.
- Create NAS network storage with Raspberry Pi and Sambaone of the most frequent uses of the raspberry pi is to create a local media storage system, commonly referred to as a nas. today, tipsmake.com will explain how to create a nas on a raspberry pi using samba software.
- How to create a Plex Server on Raspberry Pi 4plex is a great toolkit, a media server software that allows you to stream movies and tv shows directly to any plex client. learn how to build an independent plex server from your raspberry pi 4 and hard drive.