Skip to content

Instantly share code, notes, and snippets.

@beaucarnes
Created December 10, 2020 15:42
Show Gist options
  • Save beaucarnes/51ec37412ab181a2e3fd320ee474b671 to your computer and use it in GitHub Desktop.
Save beaucarnes/51ec37412ab181a2e3fd320ee474b671 to your computer and use it in GitHub Desktop.
Python Server for Discord Bot
from flask import Flask
from threading import Thread
app = Flask('')
@app.route('/')
def home():
return "Hello. I am alive!"
def run():
app.run(host='0.0.0.0',port=8080)
def keep_alive():
t = Thread(target=run)
t.start()
@Cyber71Gaming
Copy link

tnx

@khushalsonawat
Copy link

I tried this tutorial and had the question if the repl.it database could be used on our local machines as well.
And help is appreciated!

Copy link

ghost commented Mar 31, 2021

This is amazing thank you Beau

@Chhunneng
Copy link

Good Idea

Copy link

ghost commented May 14, 2021

Hey I really appreciate the tutorial. I was wondering if anyone else was experiencing an issue with versions of replit and flask.

[SolverProblemError] Because no versions of replit match >3.0.0,<4.0.0 and replit (3.0.0) depends on flask (>=1.1.2,<2.0.0), replit (>=3.0.0,<4.0.0) requires flask (>=1.1.2,<2.0.0). So, because repl-python3-practicebot depends on both flask (^2.0.0) and replit (^3.0.0), version solving failed. exit status 1

This error only came up after I added the database code. I would be grateful for any help.

@Ked29
Copy link

Ked29 commented May 16, 2021

Hey I really appreciate the tutorial. I was wondering if anyone else was experiencing an issue with versions of replit and flask.

[SolverProblemError] Because no versions of replit match >3.0.0,<4.0.0 and replit (3.0.0) depends on flask (>=1.1.2,<2.0.0), replit (>=3.0.0,<4.0.0) requires flask (>=1.1.2,<2.0.0). So, because repl-python3-practicebot depends on both flask (^2.0.0) and replit (^3.0.0), version solving failed. exit status 1

This error only came up after I added the database code. I would be grateful for any help.

Yes I don't think this works anymore... I had the same thing happen

@prashant2-4-4
Copy link

[SolverProblemError] Because no versions of replit match >3.0.0,<4.0.0 and replit (3.0.0) depends on flask (>=1.1.2,<2.0.0), replit (>=3.0.0,<4.0.0) requires flask (>=1.1.2,<2.0.0). So, because repl-python3-practicebot depends on both flask (^2.0.0) and replit (^3.0.0), version solving failed. exit status 1

same problem plz help

@manasa-sm
Copy link

Hey I really appreciate the tutorial. I was wondering if anyone else was experiencing an issue with versions of replit and flask.

[SolverProblemError] Because no versions of replit match >3.0.0,<4.0.0 and replit (3.0.0) depends on flask (>=1.1.2,<2.0.0), replit (>=3.0.0,<4.0.0) requires flask (>=1.1.2,<2.0.0). So, because repl-python3-practicebot depends on both flask (^2.0.0) and replit (^3.0.0), version solving failed. exit status 1

This error only came up after I added the database code. I would be grateful for any help.

facing with the same issue

@phanhoang1366
Copy link

Hey I really appreciate the tutorial. I was wondering if anyone else was experiencing an issue with versions of replit and flask.
[SolverProblemError] Because no versions of replit match >3.0.0,<4.0.0 and replit (3.0.0) depends on flask (>=1.1.2,<2.0.0), replit (>=3.0.0,<4.0.0) requires flask (>=1.1.2,<2.0.0). So, because repl-python3-practicebot depends on both flask (^2.0.0) and replit (^3.0.0), version solving failed. exit status 1
This error only came up after I added the database code. I would be grateful for any help.

facing with the same issue

found the solution! you need to add flask = "1.1.4" line to pyproject.toml before the [tool.poetry.dev-dependencies] line

@Oeshik
Copy link

Oeshik commented May 22, 2021

Hey I really appreciate the tutorial. I was wondering if anyone else was experiencing an issue with versions of replit and flask.
[SolverProblemError] Because no versions of replit match >3.0.0,<4.0.0 and replit (3.0.0) depends on flask (>=1.1.2,<2.0.0), replit (>=3.0.0,<4.0.0) requires flask (>=1.1.2,<2.0.0). So, because repl-python3-practicebot depends on both flask (^2.0.0) and replit (^3.0.0), version solving failed. exit status 1
This error only came up after I added the database code. I would be grateful for any help.

facing with the same issue

found the solution! you need to add flask = "1.1.4" line to pyproject.toml before the [tool.poetry.dev-dependencies] line

thank you so much you beautiful human being

@Chelsi-create
Copy link

Hey I really appreciate the tutorial. I was wondering if anyone else was experiencing an issue with versions of replit and flask.
[SolverProblemError] Because no versions of replit match >3.0.0,<4.0.0 and replit (3.0.0) depends on flask (>=1.1.2,<2.0.0), replit (>=3.0.0,<4.0.0) requires flask (>=1.1.2,<2.0.0). So, because repl-python3-practicebot depends on both flask (^2.0.0) and replit (^3.0.0), version solving failed. exit status 1
This error only came up after I added the database code. I would be grateful for any help.

facing with the same issue

found the solution! you need to add flask = "1.1.4" line to pyproject.toml before the [tool.poetry.dev-dependencies] line

thank you so much for this solution, this is working!

@Indianjuf
Copy link

Nice

@zenix912
Copy link

bro im a 12 year old trying to make a bot for my fortnite clan can some one tell me what this is?

@Chhunneng
Copy link

bro im a 12 year old trying to make a bot for my fortnite clan can some one tell me what this is?

This one we use to keep bot still work after you left the server.

@zenix912
Copy link

bro i still dont understand how this thing works bro

@zenix912
Copy link

i,ve been coding for 2 hours yet i still dont get it bro

@zenix912
Copy link

just for my clan

@Chhunneng
Copy link

bro i still dont understand how this thing works bro

Here you can check the video about it. He will explain how it works.

@Onija-Dissanayake
Copy link

Tysm

@Onija-Dissanayake
Copy link

Tysm

@xtho25
Copy link

xtho25 commented Dec 14, 2021

I am not getting the link for a reason. Please help

@AhmeddTerminator
Copy link

the correct code is :

@AhmeddTerminator
Copy link

import discord
import random

TOKEN = 'OTIwOTUzNTk3ODQyMzIxNDA4.Ybr24A.V5i-XSMPCDP8FrLWbLjseIE5MZY'

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):
username = str(message.author).split('#')[0]
user_message = str(message.content)
channel = str(message.channel.name)
print(f'{username}: {user_message} ({channel})')

if message.author == client.user:
    return

if message.channel.name == 'general':
    if user_message.lower() == 'hello':
        await message.channel.send(f'Hello {username}')
        return
    elif user_message.lower() == "bye":
        await message.channel.send(f'see you later{username}')
        return
    elif user_message.lower() == "!random":
        response = f'This is your random number: {random.randrange(1000000)}'
        await message.channel.send(response)
        return

client.run(TOKEN)

@TecFuture
Copy link

I did everything here but I get the error:
Traceback (most recent call last):
File "main.py", line 4, in
import keep_alive
ModuleNotFoundError: No module named 'keep_alive'

@dechire20
Copy link

I ran to an error I don't know how to solve it .
I have used this for the last 5 months and didn't run into any error after looking into my replit I saw this and my bot doesn't run anymore.

  • Serving Flask app '' (lazy loading)
  • Environment: production
    WARNING: This is a development server. Do not use it in a production deployment.
    Use a production WSGI server instead.
  • Debug mode: off
  • Running on all addresses.
    WARNING: This is a development server. Do not use it in a production deployment.
  • Running on http://172.18.0.177:8080/ (Press CTRL+C to quit)
    Traceback (most recent call last):
    File "main.py", line 46, in
    client.run(my_secret)
    File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 723, in run
    return future.result()
    File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 702, in runner
    await self.start(*args, **kwargs)
    File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 665, in start
    await self.login(*args, bot=bot)
    File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 511, in login
    await self.http.static_login(token.strip(), bot=bot)
    File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/http.py", line 300, in static_login
    data = await self.request(Route('GET', '/users/@me'))
    File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/http.py", line 216, in request
    raise HTTPException(r, data)
    discord.errors.HTTPException: 429 Too Many Requests (error code: 0):
<title>Access denied | discord.com used Cloudflare to restrict access</title> <script type="text/javascript"> (function(){if(document.addEventListener&&window.XMLHttpRequest&&JSON&&JSON.stringify){var e=function(a){var c=document.getElementById("error-feedback-survey"),d=document.getElementById("error-feedback-success"),b=new XMLHttpRequest;a={event:"feedback clicked",properties:{errorCode:1015,helpful:a,version:1}};b.open("POST","https://sparrow.cloudflare.com/api/v1/event");b.setRequestHeader("Content-Type","application/json");b.setRequestHeader("Sparrow-Source-Key","c771f0e4b54944bebf4261d44bd79a1e"); b.send(JSON.stringify(a));c.classList.add("feedback-hidden");d.classList.remove("feedback-hidden")};document.addEventListener("DOMContentLoaded",function(){var a=document.getElementById("error-feedback"),c=document.getElementById("feedback-button-yes"),d=document.getElementById("feedback-button-no");"classList"in a&&(a.classList.remove("feedback-hidden"),c.addEventListener("click",function(){e(!0)}),d.addEventListener("click",function(){e(!1)}))})}})(); </script> <script defer src="https://api.radar.cloudflare.com/beacon.js"></script> <script async src='/cdn-cgi/bm/cv/669835187/api.js'></script>

Error 1015

Ray ID: 6df521272f635fc8 • 2022-02-18 06:16:56 UTC

You are being rate limited

  <section class="w-240 lg:w-full mx-auto mb-8 lg:px-8">
      <div id="what-happened-section" class="w-1/2 md:w-full">
        <h2 class="text-3xl leading-tight font-normal mb-4 text-black-dark antialiased" data-translate="what_happened">What happened?</h2>
        <p>The owner of this website (discord.com) has banned you temporarily from accessing this website.</p>
        
      </div>

      
  </section>

  
  <div class="feedback-hidden py-8 text-center" id="error-feedback">
     <div id="error-feedback-survey">
        Was this page helpful?
        <button class="border border-solid bg-white cf-button cursor-pointer ml-4 px-4 py-2 rounded" id="feedback-button-yes" type="button">Yes</button>
        <button class="border border-solid bg-white cf-button cursor-pointer ml-4 px-4 py-2 rounded" id="feedback-button-no" type="button">No</button>
     </div>
     <div class="feedback-success feedback-hidden" id="error-feedback-success">
        Thank you for your feedback!
     </div>
  </div>
  

  <div class="cf-error-footer cf-wrapper w-240 lg:w-full py-10 sm:py-4 sm:px-8 mx-auto text-center sm:text-left border-solid border-0 border-t border-gray-300">

Cloudflare Ray ID: 6df521272f635fc8 Your IP: 34.82.20.192 Performance & security by Cloudflare

</div><!-- /#cf-error-details -->
<script type="text/javascript"> window._cf_translation = {}; </script> <script type="text/javascript">(function(){window['__CF$cv$params']={r:'6df521272f635fc8',m:'fPqPP3uW0OfhczLfXbedaKsQs0mU.zfzvW3J2hfWEp4-1645165016-0-AQOfaTB6OLjNlnNDPVGkIBNeBEJV/qiMqlQvp/qOM5+VpzBQrPVqqUUndAkLhBo/1ZtAvRVf4TWIXB+9KuArRMMQNClyGw88ZGf2Nm/H+MDnlb+pqXI5kTyZSFg+dsL9jb9ztbF+ghyfhOD8cbHUz50=',s:[0xff0c6a9012,0x84f9054991],}})();</script>

@sunbeamed
Copy link

help
Traceback (most recent call last):
File "site.py", line 1, in
from flask import Flask
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/flask/init.py", line 14, in
from jinja2 import escape
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/jinja2/init.py", line 12, in
from .environment import Environment
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/jinja2/environment.py", line 25, in
from .defaults import BLOCK_END_STRING
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/jinja2/defaults.py", line 3, in
from .filters import FILTERS as DEFAULT_FILTERS # noqa: F401
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/jinja2/filters.py", line 13, in
from markupsafe import soft_unicode
ImportError: cannot import name 'soft_unicode' from 'markupsafe' (/opt/virtualenvs/python3/lib/python3.8/site-packages/markupsafe/init.py)

@sunbeamed
Copy link

i,ve been coding for 2 hours yet i still dont get it bro

same

@phanhoang1366
Copy link

help Traceback (most recent call last): File "site.py", line 1, in from flask import Flask File "/opt/virtualenvs/python3/lib/python3.8/site-packages/flask/**init**.py", line 14, in from jinja2 import escape File "/opt/virtualenvs/python3/lib/python3.8/site-packages/jinja2/**init**.py", line 12, in from .environment import Environment File "/opt/virtualenvs/python3/lib/python3.8/site-packages/jinja2/environment.py", line 25, in from .defaults import BLOCK_END_STRING File "/opt/virtualenvs/python3/lib/python3.8/site-packages/jinja2/defaults.py", line 3, in from .filters import FILTERS as DEFAULT_FILTERS # noqa: F401 File "/opt/virtualenvs/python3/lib/python3.8/site-packages/jinja2/filters.py", line 13, in from markupsafe import soft_unicode ImportError: cannot import name 'soft_unicode' from 'markupsafe' (/opt/virtualenvs/python3/lib/python3.8/site-packages/markupsafe/**init**.py)

this can easily be fixed by downgrading markupsafe, which can be done by adding markupsafe = "2.0.1" to pyproject.toml before the [tool.poetry.dev-dependencies] line

@phanhoang1366
Copy link

I ran to an error I don't know how to solve it . I have used this for the last 5 months and didn't run into any error after looking into my replit I saw this and my bot doesn't run anymore.

  • Serving Flask app '' (lazy loading)
  • Environment: production
    WARNING: This is a development server. Do not use it in a production deployment.
    Use a production WSGI server instead.
  • Debug mode: off
  • Running on all addresses.
    WARNING: This is a development server. Do not use it in a production deployment.
  • Running on http://172.18.0.177:8080/ (Press CTRL+C to quit)
    Traceback (most recent call last):
    File "main.py", line 46, in
    client.run(my_secret)
    File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 723, in run
    return future.result()
    File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 702, in runner
    await self.start(*args, **kwargs)
    File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 665, in start
    await self.login(*args, bot=bot)
    File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 511, in login
    await self.http.static_login(token.strip(), bot=bot)
    File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/http.py", line 300, in static_login
    data = await self.request(Route('GET', '/users/@me'))
    File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/http.py", line 216, in request
    raise HTTPException(r, data)
    discord.errors.HTTPException: 429 Too Many Requests (error code: 0):
<title>Access denied | discord.com used Cloudflare to restrict access</title> <script type="text/javascript"> (function(){if(document.addEventListener&&window.XMLHttpRequest&&JSON&&JSON.stringify){var e=function(a){var c=document.getElementById("error-feedback-survey"),d=document.getElementById("error-feedback-success"),b=new XMLHttpRequest;a={event:"feedback clicked",properties:{errorCode:1015,helpful:a,version:1}};b.open("POST","https://sparrow.cloudflare.com/api/v1/event");b.setRequestHeader("Content-Type","application/json");b.setRequestHeader("Sparrow-Source-Key","c771f0e4b54944bebf4261d44bd79a1e"); b.send(JSON.stringify(a));c.classList.add("feedback-hidden");d.classList.remove("feedback-hidden")};document.addEventListener("DOMContentLoaded",function(){var a=document.getElementById("error-feedback"),c=document.getElementById("feedback-button-yes"),d=document.getElementById("feedback-button-no");"classList"in a&&(a.classList.remove("feedback-hidden"),c.addEventListener("click",function(){e(!0)}),d.addEventListener("click",function(){e(!1)}))})}})(); </script> <script defer src="https://api.radar.cloudflare.com/beacon.js"></script> <script async src='/cdn-cgi/bm/cv/669835187/api.js'></script> Please enable cookies. # Error 1015 Ray ID: 6df521272f635fc8 • 2022-02-18 06:16:56 UTC ## You are being rate limited ```

What happened?

The owner of this website (discord.com) has banned you temporarily from accessing this website.

  </div>
Was this page helpful? Yes No
Thank you for your feedback!
```

Cloudflare Ray ID: 6df521272f635fc8 • Your IP: 34.82.20.192 • Performance & security by Cloudflare

</div><!-- /#cf-error-details -->
<script type="text/javascript"> window._cf_translation = {}; </script> <script type="text/javascript">(function(){window['__CF$cv$params']={r:'6df521272f635fc8',m:'fPqPP3uW0OfhczLfXbedaKsQs0mU.zfzvW3J2hfWEp4-1645165016-0-AQOfaTB6OLjNlnNDPVGkIBNeBEJV/qiMqlQvp/qOM5+VpzBQrPVqqUUndAkLhBo/1ZtAvRVf4TWIXB+9KuArRMMQNClyGw88ZGf2Nm/H+MDnlb+pqXI5kTyZSFg+dsL9jb9ztbF+ghyfhOD8cbHUz50=',s:[0xff0c6a9012,0x84f9054991],}})();</script>

being rate-limited in replit isn't rare at all, when someone possibly creates a malicious bot and spammed discord until death
if that happens, you can make a simple try catch in the last line:
from subprocess import run
try: client.run(os.environ['TOKEN']) except: run(['kill', '1'])
(it only checks the api in start-up, it doesn't work if the bot died halfway)
or, you can make another thread that checks every 300-600 seconds if connecting to discord api (https://discord.com/api/v9/) returns 429 using urllib and threading, but i'm too lazy for that :p

@lab596
Copy link

lab596 commented Aug 31, 2022

I hate replit soo much, this problem still hasn't been fixed yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment