discord bot raspberry pi code example

Example: how to host a discord bot on a raspberry pi

# 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