Reputation: 11
I'm trying to put my discord bot on my raspberry pi (using ssh to code it) and as soon as I close terminal the bot stops working and the guide I've used: https://www.gngrninja.com/code/2017/3/24/python-create-discord-bot-on-raspberry-pi
I've looked everywhere and I can't find anything, I have been using replit but I have decided to switch to my raspberry pi and I have ran into this problem
My code (the '.' is a racist word that I've changed):
import discord
client = discord.Client()
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('$hello'):
await message.channel.send('Hello!๐ ')
emoji = '\N{THUMBS UP SIGN}'
await message.add_reaction(emoji)
if message.content.startswith('$trainingt'):
channel = client.get_channel
(886960656081887282)
await channel.send('test....')
if message.author == client.user:
return
if message.content.startswith('$ping'):
await message.channel.send('Pong! :ping_pong:')
emoji = '\N{THUMBS UP SIGN}'
await message.add_reaction(emoji)
if message.author == client.user:
return
if message.content.startswith('$cmds'):
await message.channel.send('I sent them through your dms!๐')
if message.content.startswith('$help'):
embedVar = discord.Embed(title="Hello", description="If you need help", color=0x71368a)
embedVar.add_field(name="Help", value="If you need help with my commands, the command is $cmds and it will send you a dm! If you need help with anything dm any of the heads or me <@!727846710029713409>", inline=False)
await message.channel.send(embed=embedVar)
if message.author == client.user:
return
if message.content.startswith('$owner'):
await message.channel.send('My owner is <@!727846710029713409> !')
if message.author == client.user:
return
if message.content.startswith('$hi'):
channel = client.get_channel(816926625551220736)
await channel.send('Hello howโs everyones day?')
emoji = '\N{THUMBS UP SIGN}'
await message.add_reaction(emoji)
if message.author == client.user:
return
if message.content.startswith('$how are you?'):
channel = client.get_channel(816926625551220736)
await channel.send('Iโm good you?')
emoji = '\N{THUMBS UP SIGN}'
await message.add_reaction(emoji)
if message.author == client.user:
return
if message.content.startswith('$sad'):
await message.author.send('Donโt be sad! listen to this song https://m.youtube.com/watch?v=ZbZSe6N_BXs')
if message.content.startswith('$sad'):
await message.channel.send('check your dms ๐!')
emoji = '\N{THUMBS UP SIGN}'
await message.add_reaction(emoji)
if message.content.startswith('$bruh'):
await message.channel.send('https://cdn.discordapp.com/attachments/816926625551220736/895971333651963924/image0.jpg')
emoji = '\N{THUMBS UP SIGN}'
await message.add_reaction(emoji)
if message.content.startswith('$sm'):
await message.author.send(' click this link! for the profile pictures! https://drive.google.com/drive/folders/1slb9g_HvFLVgPypfOAyNYqx6cgwjdhFI?usp=sharing')
emoji = '\N{THUMBS UP SIGN}'
await message.add_reaction(emoji)
if message.content.startswith('$sm'):
await message.delete()
if message.content.startswith('$sm'):
await message.channel.send('check your dms!')
if message.content.startswith('$heads'):
embedVar = discord.Embed(title="hello", description="these are the heads", color=0x71368a)
embedVar.add_field(name="the heads", value="the 01 <@!521351916937019432>. the 02 <@!756035683209969775> the 03 <@!481730153798434817> the 04 <@!695068421880152074> the 05 <@!277102202026459136> the 06 <@!685784710047203348> the 07 (vacant) and the bot manager <@!727846710029713409>", inline=False)
await message.channel.send(embed=embedVar)
emoji = '\N{THUMBS UP SIGN}'
await message.add_reaction(emoji)
if message.content.startswith('$cmds'):
embedVar = discord.Embed(title="hello", description="hello these are my commands!", color=0x71368a)
embedVar.set_thumbnail(url="https://media3.giphy.com/media/CpcpDSci3ljCU/giphy.gif?cid=ecf05e47il4ht62st4ri29liiaddpcm2edqs9iszt047ynmw&rid=giphy.gif&ct=g")
embedVar.add_field(name="$sm", value="This command sends you a dm with a link to all the SM profile pictures", inline=False)
embedVar.add_field(name="$ping or $pong", value="play ping pong with me", inline=False)
embedVar.add_field(name="$update", value="Look at the most recent update for the bot", inline=False)
embedVar.add_field(name="$sad", value="The bot sends you a happy DM ", inline=False)
embedVar.add_field(name="$owner", value="Have a look at who coded me!", inline=False)
embedVar.add_field(name="$requestt", value="Request a training!", inline=False)
embedVar.add_field(name="$spam", value="sends you a spammed message", inline=False)
embedVar.add_field(name="$request interview", value="Request an interview!", inline=False)
embedVar.add_field(name="$dead", value="sends you a link to 'f yo homie dead'", inline=False)
embedVar.add_field(name="and alot more commands coming soon!", value="thanks", inline=False)
embedVar.set_footer(text="coded by whatic!")
await message.author.send(embed=embedVar)
emoji = '\N{THUMBS UP SIGN}'
await message.add_reaction(emoji)
if message.content.startswith('$training1'):
mention = message.author.mention
response = f" {mention}, will be hosting a training today in 1 hour <@&817077039102164994> Be sure to come with your UNIFORM and LOAD-OUT ready. The Uniform can be found in ๐ด-๐๐๐๐๐ ๐ฃ๐๐ค Channel in the discord. If you do not mark your attendance you will not attend. Applicants that intend on attending please mark attendance with a :thumbsup:"
channel = client.get_channel(817187149514276954)
await channel.send(response)
emoji = '\N{THUMBS UP SIGN}'
await message.add_reaction(emoji)
if message.content.startswith('$near'):
mention = message.author.mention
response = f" {mention}, training in 5 mins!! <@&817077039102164994> "
channel = client.get_channel(817187149514276954)
await channel.send(response)
emoji = '\N{THUMBS UP SIGN}'
await message.add_reaction(emoji)
if message.content.startswith('.'):
await message.delete()
if message.content.startswith('.'):
await message.channel.send('dont say that!')
if message.content.startswith('.'):
mention = message.author.mention
response = f" {mention}, said a racist word! <@&817072866913812490>"
channel = client.get_channel(887320940575350824)
await channel.send(response)
if message.content.startswith('.'):
await message.delete()
if message.content.startswith('.'):
await message.channel.send('dont say that!')
if message.content.startswith('.'):
mention = message.author.mention
response = f" {mention}, said a homophobic word! <@&817072866913812490>"
channel = client.get_channel(887320940575350824)
await channel.send(response)
if message.content.startswith('.'):
await message.delete()
if message.content.startswith('.'):
await message.channel.send('dont say that!')
if message.content.startswith('.'):
mention = message.author.mention
response = f" {mention}, said a racist word! <@&817072866913812490>"
channel = client.get_channel(887320940575350824)
await channel.send(response)
if message.content.startswith('.'):
await message.delete()
if message.content.startswith('.'):
await message.channel.send('dont say that!')
if message.content.startswith('.'):
mention = message.author.mention
response = f" {mention}, said a racist word! <@&817072866913812490>"
channel = client.get_channel(887320940575350824)
await channel.send(response)
if message.content.startswith('.'):
await message.delete()
if message.content.startswith('.'):
await message.channel.send('dont say that!')
if message.content.startswith('.'):
mention = message.author.mention
response = f" {mention}, said a racist word! <@&817072866913812490>"
channel = client.get_channel(887320940575350824)
await channel.send(response)
if message.content.startswith('$update'):
mention = message.author.mention
response = f" {mention},for the most recent update click the link! https://docs.google.com/document/d/e/2PACX-1vRRqeRM6DPanEM2tLdIBdGO-9QzT5nyh_xQo_4NcXVgOm-wdKhTmb2ckLuxiTjBu33zrJXjzXMx0J5M/pub"
channel = client.get_channel(816926794401054731)
await channel.send(response)
if message.content.startswith('$requestt'):
channel = client.get_channel(887320940575350824)
embedVar = discord.Embed(title="hello", description="", color=0x71368a)
embedVar.add_field(name="๐", value=f"{message.author.mention} has requested a training! please do $aceptt to post a training or dm the bot $training30 to post a training!", inline=False)
await channel.send(embed=embedVar)
emoji = '\N{THUMBS UP SIGN}'
await message.add_reaction(emoji)
if message.content.startswith('$training30'):
channel = client.get_channel(817187149514276954)
await channel.send('<@&817077039102164994>')
if message.content.startswith('$training30'):
channel = client.get_channel(817187149514276954)
embedVar = discord.Embed(title="Training in 30 mins!", description= f" {message.author.mention} will be hosting a training today in 30 mins <@&817077039102164994> Be sure to come with your uniform and load-out ready. The Uniforms can be found in #:levitate:-๐๐๐๐๐ ๐ฃ๐๐ค channel in the discord. If you do not mark your attendance you will not be counted in the training so please mark your attendance. Applicants that intend on attending please mark your attendance with a :thumbsup:.", color=0x71368a)
embedVar.add_field(name="๐", value=f" DM {message.author.mention} if you have any questions", inline=False)
await channel.send(embed=embedVar)
emoji = '\N{THUMBS UP SIGN}'
await message.add_reaction(emoji)
if message.content.startswith('$requestt'):
mention = message.author.mention
response = f" {mention}, training cetified has been notified! that you you are avalible for a training!"
await message.author.send(response)
emoji = '\N{THUMBS UP SIGN}'
await message.add_reaction(emoji)
if message.content.startswith('$acceptt'):
mention = message.author.mention
response = f" {mention}, will be hosting a training today in 30 mins <@&817077039102164994> Be sure to come with your uniform and load-out ready. The Uniforms can be found in #:levitate:-๐๐๐๐๐ ๐ฃ๐๐ค channel in the discord. If you do not mark your attendance you will not be counted in the training so please mark your attendance. Applicants that intend on attending please mark your attendance with a :thumbsup:. "
channel = client.get_channel(817187149514276954)
await channel.send(response)
emoji = '\N{THUMBS UP SIGN}'
await message.add_reaction(emoji)
if message.content.startswith('$he2'):
embedVar = discord.Embed(title="test", description=f"hello!, {message.author.mention} ", inline=False)
await message.channel.send(embed=embedVar)
emoji = '\N{THUMBS UP SIGN}'
await message.add_reaction(emoji)
if message.content.startswith('$poo'):
await message.channel.send(f"Bugger off, {message.author.mention}!")
if message.content.startswith('$activityp'):
channel = client.get_channel(816926625551220736)
embedVar = discord.Embed(title="hello", description="", color=0x71368a)
embedVar.add_field(name="JOIN THOSE RADIOS!", value=f"{message.author.mention} would like more activity! lets get in those radios!!!", inline=False)
await channel.send(embed=embedVar)
emoji = '\N{THUMBS UP SIGN}'
await message.add_reaction(emoji)
if message.content.startswith('$activityp'):
await message.author.send('everyone has been notified!')
await message.delete()
if message.content.startswith('$activityp'):
channel = client.get_channel(816926625551220736)
await channel.send('<@&817076146176262175>')
if message.content.startswith('$suggest'):
embedVar = discord.Embed(title="hello", description="", color=0x71368a)
embedVar.add_field(name="If you would like to suggest a feature to the bot please click on this link: ", value=f"{message.author.mention} https://docs.google.com/forms/d/1d5i5uwRArX7aPFu8ut1nyrD4YZVUCkf-vbjCc15IjOE/edit", inline=False)
await message.author.send(embed=embedVar)
emoji = '\N{THUMBS UP SIGN}'
await message.add_reaction(emoji)
if message.content.startswith('$spam'):
embedVar = discord.Embed(title="SPAM!", description="", color=0x71368a)
embedVar.add_field(name="๐", value="๐ ๐ค ๐ โ ๐ ๐ ๐ค ๐ค โ๏ธ ๐ค ๐ค ๐ค ๐ค ๐ ๐ ๐ ๐ ๐ โ๏ธ ๐ ๐ โ ๐ ๐ค ๐ค ๐ ๐ ๐ ๐คฒ ๐ค ๐ โ๏ธ ๐
๐คณ ๐ช ๐ฆพ ๐ฆต ๐ฆฟ ๐ฆถ ๐ฃ ๐ ๐ฆป ๐ ๐ซ ๐ซ ๐ง ๐ฆท ๐ฆด ๐ ๐ ๐
๐ ๐ ๐ฉธ ๐ถ ๐ง ๐ง ๐ฆ ๐ฉ ๐ง ๐จ ๐ฉโ๐ฆฑ ๐งโ๐ฆฑ ๐จโ๐ฆฑ ๐ฉโ๐ฆฐ ๐งโ๐ฆฐ ๐จโ๐ฆฐ ๐ฑโโ๏ธ ๐ฑ ๐ฑโโ๏ธ ๐ฉโ๐ฆณ ๐งโ๐ฆณ ๐จโ๐ฆณ ๐ฉโ๐ฆฒ ๐งโ๐ฆฒ ๐จโ๐ฆฒ ๐ง ๐ต ๐ง ๐ด ๐ฒ ๐ณโโ๏ธ ๐ณ ๐ณโโ๏ธ ๐ง ๐ฎโโ๏ธ ๐ฎ ๐ฎโโ๏ธ ๐ทโโ๏ธ ๐ท ๐ทโโ๏ธ ๐โโ๏ธ ๐ ๐โโ๏ธ ๐ต๏ธโโ๏ธ ๐ต๏ธ ๐ต๏ธโโ๏ธ ๐ฉโโ๏ธ ๐งโโ๏ธ ๐จโโ๏ธ ๐ฉโ๐พ ๐งโ๐พ ๐จโ๐พ ๐ฉโ๐ณ ๐งโ๐ณ ๐จโ๐ณ ๐ฉโ๐ ๐งโ๐ ๐จโ๐ ๐ฉโ๐ค ๐งโ๐ค ๐จโ๐ค ๐ฉโ๐ซ ๐งโ๐ซ ๐จโ๐ซ ๐ฉโ๐ญ ๐งโ๐ญ ๐จโ๐ญ ๐ฉโ๐ป ๐งโ๐ป ๐จโ๐ป ๐ฉโ๐ผ ๐งโ๐ผ ๐จโ๐ผ ๐ฉโ๐ง ๐งโ๐ง ๐จโ๐ง ๐ฉโ๐ฌ ๐งโ๐ฌ ๐จโ๐ฌ ๐ฉโ๐จ ๐งโ๐จ ๐จโ๐จ ๐ฉโ๐ ๐งโ๐ ๐จโ๐ ๐ฉโโ๏ธ ๐งโโ๏ธ ๐จโโ๏ธ ๐ฉโ๐ ๐งโ๐ ๐จโ๐ ๐ฉโโ๏ธ ๐งโโ๏ธ ๐จโโ๏ธ ๐ฐโโ๏ธ ๐ฐ ๐ฐโโ๏ธ ๐คตโโ๏ธ ๐คต ๐คตโโ๏ธ ๐ธ ๐คด ๐ฅท ๐ฆธโโ๏ธ ๐ฆธ ๐ฆธโโ๏ธ ๐ฆนโโ๏ธ ๐ฆน ๐ฆนโโ๏ธ ๐คถ ๐งโ๐ ๐
๐งโโ๏ธ ๐ง ๐งโโ๏ธ ๐งโโ๏ธ ๐ง ๐งโโ๏ธ ๐งโโ๏ธ ๐ง ๐งโโ๏ธ ๐งโโ๏ธ ๐ง ๐งโโ๏ธ ๐งโโ๏ธ ๐ง ๐งโโ๏ธ ๐งโโ๏ธ ๐ง ๐งโโ๏ธ ๐งโโ๏ธ ๐ง ๐งโโ๏ธ ๐ผ ๐คฐ ๐คฑ ๐ฉโ๐ผ ๐งโ๐ผ ๐จโ๐ผ ๐โโ๏ธ ๐ ๐โโ๏ธ ๐โโ๏ธ ", inline=False)
await message.author.send(embed=embedVar)
emoji = '\N{THUMBS UP SIGN}'
await message.add_reaction(emoji)
if message.content.startswith('$leadershipcmds2'):
embedVar = discord.Embed(title="hello", description="my commands", color=0x71368a)
embedVar.add_field(name="commands", value="$training30 ( post a training in 30 mins)", inline=False)
embedVar.add_field(name="commands", value="$training1 ( post a training in 1 hour)", inline=False)
embedVar.add_field(name="commands", value="$activityp (pings everyone to get in radios and be more active)", inline=False)
embedVar.add_field(name="commands", value="$acceptt (if someone requests a training just do $acceptt to post a training) ", inline=False)
embedVar.add_field(name="commands", value="$near (when theres 5 minutes until the training starts)", inline=False)
embedVar.add_field(name="commands", value="and more coming soon!!)", inline=False)
embedVar.add_field(name="commands", value="$clear (then how many messages you want to clear) ", inline=False)
await message.author.send(embed=embedVar)
emoji = '\N{THUMBS UP SIGN}'
await message.add_reaction(emoji)
await message.delete()
if message.content.startswith('$request interview'):
channel = client.get_channel(888411047441072138)
embedVar = discord.Embed(title="hello", description=f"{message.author.mention} would like an interview! <@&875174557043011677>", color=0x71368a)
await channel.send(embed=embedVar)
emoji = '\N{THUMBS UP SIGN}'
await message.add_reaction(emoji)
if message.content.startswith('$request interview'):
await message.channel.send('<@&875174557043011677>')
await message.delete()
if message.content.startswith('๐ค'):
await message.channel.send('๐ค')
if message.content.startswith('๐ค'):
await message.channel.send('lets box!!')
if message.content.startswith('Whatโs up'):
await message.channel.send('the sky!')
if message.content.startswith('whats up'):
await message.channel.send('the sky!')
if message.content.startswith('$secret'):
embedVar = discord.Embed(title="hello", description=f"{message.author.mention} you have found my secret! ๐", color=0x71368a)
await message.channel.send(embed=embedVar)
emoji = '\N{THUMBS UP SIGN}'
await message.add_reaction(emoji)
if message.content.startswith('$963'):
channel = client.get_channel(816926625551220736)
embedVar = discord.Embed(title="hello", description="we are doing a 963 raid join the radio!", color=0x71368a)
await channel.send(embed=embedVar)
emoji = '\N{THUMBS UP SIGN}'
await message.add_reaction(emoji)
if message.content.startswith('$best'):
channel =client.get_channel (816926625551220736)
await channel.send('๐๐ ๐๐ค ๐ฅ๐๐ ๐๐๐ค๐ฅ!!')
if message.content.startswith('$3019'):
channel = client.get_channel(816926625551220736)
embedVar = discord.Embed(title="hello", description="we are doing a 3019 robbery join the radio!", color=0x71368a)
await channel.send(embed=embedVar)
emoji = '\N{THUMBS UP SIGN}'
await message.add_reaction(emoji)
if message.content.startswith('$event'):
channel = client.get_channel(816926625551220736)
embedVar = discord.Embed(title="hello", description="we are doing an event join the event radio!", color=0x71368a)
await channel.send(embed=embedVar)
emoji = '\N{THUMBS UP SIGN}'
await message.add_reaction(emoji)
if message.content.startswith('$dead'):
embedVar = discord.Embed(title="๐๐๐๐๐", description=" ๐ https://www.youtube.com/watch?v=qPOmWF1pheo ๐", color=0x71368a)
await message.channel.send(embed=embedVar)
emoji = '\N{THUMBS UP SIGN}'
await message.add_reaction(emoji)
if message.content.startswith('bruh'):
await message.channel.send('bruh')
if message.content.startswith('$rap'):
await message.channel.send('Its everyday bro with that Disney channel flow 5mil on youtube in 6 months,never done before passed all the competition man, PewDiePie is next! (help me i was forced to say this)')
if message.content.startswith('$gang'):
channel = client.get_channel(816926625551220736)
await channel.send('gang!')
if message.content.startswith('$god'):
await message.channel.send('The gods are: Xander, Fuzion, Phantom, Snakey and Jackson(They are in no specific order)')
if message.content.startswith('What do we think of Mee6?'):
await message.channel.send('He sucks i am way better')
if message.content.startswith('$pong'):
await message.channel.send('Ping! :ping_pong:')
emoji = '\N{THUMBS UP SIGN}'
await message.add_reaction(emoji)
if message.content.startswith('$join'):
await message.channel.send('https://cdn.discordapp.com/attachments/816926625551220736/896506787665166367/sm_bvanner.gif')
emoji = '\N{THUMBS UP SIGN}'
await message.add_reaction(emoji)
@client.event
async def on_ready():
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name='over 150 sm members!'))
print('Connected to bot: {}'.format(client.user.name))
print('Bot ID: {}'.format(client.user.id))
my_secret = ('(token taken out')
client.run(my_secret) ```
Upvotes: 0
Views: 4075
Reputation: 132
Screen is what I use and it's super easy.
sudo apt-get install screen
screen -S yourbot
CTRL+A+D
screen -ls
screen -r yourbot
Here's a link to the whole tutorial.
Upvotes: 1