how to host a discord bot on a raspberry pi

#how to create and host a Discord Bot on a rasberry pi

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

https://discordapp.com/oauth2/authorize?client_id=your_client_id_goes_here&scope=bot&permissions=0

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
**Note**

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

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

To check which version you have, run:

cat /etc/os-release
buster.png
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
libssl.PNG
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 https://www.python.org/downloads/

wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz

2. Extract the files, and enter the directory

tar xzvf Python-3.6.0.tgz
tar.PNG
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)

./configure

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

make

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
NOTE: If you are on a fresh Buster install, you may need to install the following before continuing:

sudo apt install python3-pip
sudo apt install python3-cffi
sudo pip3 install discord.py[voice] 

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

sudo python3 -m pip install -U discord.py[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

touch bot.py

    d. Edit the file

nano bot.py

    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)

@bot.event
async def on_ready():
    print('Logged in as')
    print(bot.user.name)
    print(bot.user.id)
    print('------')


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


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

bot.run(TOKEN)
    f. Save the file using CTRL+X, and "y"


    g. Run your bot!

python3 bot.py

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!

4
5

                                    # how to host a Discord Bot whith Javascript (node.js) on Linux
# i used the Raspberry pi whith Raspian

#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

https://discordapp.com/oauth2/authorize?client_id=your_client_id_goes_here&scope=bot&permissions=0

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


#create a new folder
mkdir Bot
#move into the Folder
cd Bot/

#install Discord.js
npm install discord.js

#if thats not working you need to install Npm
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs

#you get some warn messages but thats ok
#create a new javasript
pico my_bot.js
#paste this in:
const Discord = require('discord.js')
const client = new Discord.Client()

client.on('message', (receivedMessage) => {
    // Prevent bot from responding to its own messages
    if (receivedMessage.author == client.user) {
        return
    }

    receivedMessage.channel.send("Message received: " + receivedMessage.content)
})

client.login("XXXXXXXXXXX")
#replace xxxxxxxxxxxxx whith your Bot Token
#start the bot 
node my_bot.js
#it should work

4 (5 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
what is the best raspberry pi to host a discord bot How to run a discord bot on a rasberry pi discord bot in raspberry pi creating a discord bot on a raspberry pi how to use a raspberry pi as a discord bot can you host a discord bot on a raspberry pi host your discord bot with a raspberry pi discord bot host raspberry pi raspberry pi discord bot hosting raspberry pi host discord bot can you use a raspberry pi for a discord bot host a discord bot off raspberry pi how to host bots in raspberry pi discord.js how to host discord bot in raspberry pi how to host dsicord bot in raspberrypi discord bot host using raspberry pi hosting discord bot on raspberry pi discord bot raspberry pi raspberry pi host server for discord bot how to set up discord bot on raspberry pi host discord.py bot raspberry pi make a python file run all the time raspberry pi discord bot how to keep discord bot online raspberry pi discord bot python raspberyy pi exception should you host discord bot on raspberry pi discord python bot on raspberry pi 3 discord bot on raspberry pi 3 discord bot on raspberry pi discord bot on raspberry host discord bot on raspberry pi how to run a discord bot on a raspberry pi boot I am running my discord bot continously on my Raspberry Pi how to install discord.py for rasbian how to run discord.py on rasbian raspberry pi discord bot can i host discord.py on raspi zero run discord bot on raspberry pi raspberry pi for discord bot host discord bot raspberry pi how to host discord bot on raspberry pi discord bot raspberry pi send message Discord bot respari pi how to setup your raspberry pi discord how to install discord.py on raspberry pi how to host a discord bot on raspberry pi python discord bot raspberry pi how to host a discord bot on a raspberry pi how to run a discord bot on the raspberry pi java discord bot on arasberry pi how toc reate a discord bot on a raspberry pi java how to create a discord bot with a rasspberry pi how to run a discord bot on a raspberry pi host a discord bot on rasbery pi java
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source