How do I make my discord bot stay online - python

I recently made a music bot in my discord server but the problem I have is that I have to turn on the bot manually etc. and it goes offline when I turn off my computer. How can I make the bot stay online at all times, even when I'm offline?

You need to run the python script on a server, e.g. an EWS linux instance.
To do that you would need to install python on the server and place the script in the home directory and just run it via a screen.

Use a Raspberry Pi with an internet connection. Install all necessary components and then run the script in its terminal. Then, you can switch off the monitor and the bot will continue running. I recommend that solution to run the bot 24/7. If you don't have a Raspberry Pi, buy one (they're quite cheap), or buy a server to run the code on.

Related

Raspberry pi -Playing mp3 files on a remote server in a Python script

For a project i have on my Raspberry PI, i need to be able to play mp3s on a remote server on the internet thanks to a python script and access basic commands (pause, next & previous track). The mp3s can be played from a specific Directory but it can works with playlists.
I'm struggling to find the solution. VLC or MPG123 seems to not offer such possibilities (i managed to start a playlist but i cant find any way to summon basic commands such next track).
I even tried to use vlc-ctrl but it doesn't manage internet links.
Can you please help me ?

How could I create a telegram bot is always running

I created my telegram bot, and it's running successfully, but I need to keep it running till I closed my PC
You have to run it on a server. You can deploy it on Heroku for free (https://www.heroku.com/).
If you want to run it on your own computer (i.e. not on a server such as AWS or Heroku), you could look to daemonize your application. The easiest would be to use python-daemon.

How to auto restart discord bot using python

Is there any way of making my discord bot auto-restart. What i mean is say if my wifi shut off and my bot went offline the code would detect the bot went offline it would attempt to restart the bot- if it failed it would wait 5 mins then try again. NOTE: The discord bot source code is running on python 3.6.5 on a raspberry pi 3
I think it can be done by creating seccond file:
import os
while True:
os.system("yourfilename.py")
time.sleep(300)
this will run your bot 5 minutes after going offline every time that will happen

Google Speech Api Credential Error with Raspbian (Raspberry pi)

i want to make a speech to text program so i used Google Speech Api.
When i launched the code on my pc it works, but on raspberry pi it doesnt. Probably it is about Credential, but i tried so many things. For example:
i add GOOGLE_APPLICATION_CREDENTIALS with this command:
sudo nano ~/.bashrc
but it still creates error
i dont know what should i do.
You would need to restart your terminal for the commands in .bashrc to take effect. If you don't want to restart the terminal, type
export GOOGLE_APPLICATION_CREDENTIALS="<creds>"

Run terminal command as startup reacts different from manually (linux raspberry pi)

Here's a short description of what I have:
I have to raspberry pi's in a local net work. I one of them I have a .py script named watchdog.py that starts a stream and then uses a sshpass command to the other pi to display the video stream.It also has some signaling LEDs a some push buttons for control
the problem is:
If I open a terminal and run the watchdog.py script in the GUI everything runs as it should be. So I thought of running it as a service as boot and installed upstart and made it run as a service (successfully I think). The thing is. If I boot the pi and then press the button to start the streams,they wont play on the other Pi, the LEDs ligh up and all the buttons work. And even the CPU load behaves the same way, but i still don't video nor audio. I have thought of trying automatically open a terminal (LXterminal) widow and run the python scrip on that window. but I didn't want the streaming raspberry pi also booting into gui (tough I guess I would mind if that makes the whole thing work).This little thing i making the whole project useless.
What are you using to play the streams? Depending on how you boot up the second Raspberry it might not have started some daemons for audio/video playback?!
You should (if you're not already doing) write a log (import logging ;)) and write a logfile which you can track for errors.
answer moved from OP's question itself:
I found a way that seems to work so far. instead of running the python script as a service I tried running it as cron job at reboot, and it worked. now it all works straight from reboot and I have Audio and video.

Categories

Resources