Code a Discord Bot with Python - Host for Free in the Cloud
Why Stack Overflow recommends it
Stack Overflow users link it as the tutorial they followed when building a Repl.it Discord bot, and then ask about errors in the encouragement list, database, or keep-alive steps.
Recommended by 1 people across 1 different months, 2021 to 2023.
What it is
A freeCodeCamp.org tutorial by Beau Carnes that walks through building a Discord bot in Python, running it on Repl.it, storing settings in Repl.it's built-in database, and keeping it alive with a Flask web server and Uptime Robot. It ends with a GitHub webhook bot.
What people said
Recommends user16186190 · 2021-08 · Stack Overflow · on “Discord bot using python”
You can technically make your bot run 24/7 for free by using UptimeRobot with repl.it, i'm also new to the discord.py scene but i've managed to make this happen [this video] thats the link for a quick tutorial, but heres the rough explanation go to UptimeRobot and create an account, then add a new monitor with your discord.py's link (repl link), then the website will ping your code every 5 minutes which will make your bot not sleep also create a new .py file called keep_alive next to ur discord.py file and copy this code in 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 k
Cites Takashii · 2021-08 · Stack Overflow · on “Concatenate list in python (Discord Bot)”
I wanted to program a bot in python. I'm currently following this Tutorial [this video] . As I tried to implement the options variable (40:55) everything was fine but as I wanted to test the bot in Discord (currently at min 48:19) the bot doesn't add the new encouragement. This is my code: options = starter_encouragements if "encouragements" in db.keys(): options = options + db['encouragements'] And this is the starter_encouragements list: starter_encouragements = [ "Cheer up!", "Hang in there!", "You are a great person / bot!" ] The error message: [LINK]
Cites user15740892 · 2021-10 · Stack Overflow · on “I'm new to making a discord bot with python, and I'm having trouble with it. I send "$hello" to get a response, but nothing happens”
So, I'm using replit.com to make the bot, and the bot comes online just fine. I type in $hello and expect to get a response saying "Commander". I do that, but the bot doesn't reply back. I based this script off a video on Youtube [this video] . I'm guessing it could be something to do with my code, or the discord bot permissions. Any help/ advice would be appreciated, thanks. import discord import os import time client = discord.Client() @client.event async def on_ready(): print('We have broken into american server farms as {0.user}'.format(client)) time.sleep(1) print("Accessing private data...") time.sleep(2) print("Installing malware...") time.sleep(2) print("Extracting stolen files...") time.
Cites RainOfPain125 · 2021-11 · Stack Overflow · on “Following a Python tutorial, am getting "TypeError: can only concatenate list (not "ObservedList") to list”
I am following this tutorial [this video] word-by-word and adding my own # notes to every single line. Everything he explains makes sense up until the point where his code works but mine does not, despite being almost a direct copy. Ignoring exception in on_message Traceback (most recent call last): File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event await coro(*args, **kwargs) File "main.py", line 59, in on_message options = options + db["encouragements"] #we will add those to the list of generic encouragements to create a full list of encouragements TypeError: can only concatenate list (not "ObservedList") to list The referenced line is me tryi
Cites Snickzoryx · 2021-11 · Stack Overflow · on “How do I solve an index error (and some other things too)?”
I am programming a discord bot using the following link: [this video] It's a bot that's meant to give an inspiring message when called, and users can add and delete said messages as well. The problem I am facing : A) Whenever I type anything, it gives the received command of 'New encouraging message added', even though I'm not calling that function. B) The code itself is giving me an error stating that the list index is out of range. For reference, here is the block of code in which the error message is occurring, and the range of which I suspect the error to be at. The actual error is the line towards the bottom: index = int(msg.split("+del",1)[1])'): And here is the code if msg.startswith('+ins
Cites Snickzoryx · 2021-11 · Stack Overflow · on “How do I stop this error message from occurring?”
So I'm coding a discord bot that gives nice messages when it recognizes certain keywords, and users are able to add and delete their own messages. However, when I tried to delete a message on discord, the following response came from the bot: ObservedList(value=["You're an amazing person.", 'You are amazing.', '"It's not who we are inside, but what we do that defines us." -Rachel Dawes, Batman Begins', 'You are amazing.', "You're the best person you can be.", 'You are an amazing person ']) I'm not sure why this is happening, as I'm following a video to make this bot, which can be viewed here: [this video] For reference, here is the range of code where I suspect there might be an error: def delete
Cites MuffinHeadLord · 2021-12 · Stack Overflow · on “Discord bot is not going online”
I use repl.it to make my Discord bot. I used Python and followed this tutorial: [this video] and here is my code: import discord import os 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!') my_secret = os.environ['token']
Cites Elytra · 2021-12 · Stack Overflow · on “Ignoring Exception in_onmessage”
I am new to making Discord Bots using Discord API and python, and apparently my code is acting a bit strange since i added Databases, i have used replit for the coding. My code is: import discord import os import requests import json client = discord.Client() def get_quote(): response = requests.get(" [LINK] ") json_data = json.loads(response.text) quote = json_data[0]['q'] + " -" + json_data[0]['a'] return quote @client.event async def on_ready(): print('{0.user}'.format(client) + ' has successfully logged in.') @client.event async def on_message(message): if message.author == client.user: return if message.content.startswith('.ltt help'): await message.channel.send('hello') if input.conten
Cites ThisBadTeamate · 2022-03 · Stack Overflow · on “discord.py bot running flask wen server continuously going down”
I use uptimerobot too... I dont have problems with it. This is my code. 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() Closely the same, only i have spaces in between. make sure you have everything the correct way setup in Uptimerobot itself. I see you use the ping function of uptimerobot. I use HTML, maybe thats the big difference. To get the HTML link watch this video: [this video] and go to 1:03:48!
Cites Rick · 2022-04 · Stack Overflow · on “How can I get my code running 24/7 on replit without it only working once and then my bot also not working?”
I made code for my discord bot and used UptimeRobot to keep it running constantly but then it my bot just stopped working randomly and I'm not sure why. It worked once and maybe ran for a few hours and now it completely won't work, even if I get rid of the 'keep_alive' code. UptimeRobot - [LINK] Discord Bot Tutorial - [this video] | Time - 58:47 Main: [Start of code] import os import random import discord from keep_alive import keep_alive [ALL MY CODE/COMMANDS] Then at the end of is this [my commands] ----> keep_alive() my_secret = os.environ['TOKEN'] client.run[my_secret] [NEW FILE-KEEP_ALIVE.PY] from flask import Flask from threading import Thread app = Flask('') @app.route('/') def home(): ret