Tutorial: Building a Discord Bot with Python
h
GarethDwyer1 (229)

Hey all, I published this tutorial on writing chatbots with Python and Discord a few weeks ago and I'm excited to share it with you here now. I'm watching the comments here and over at codementor so let me know if you have any questions.

https://www.codementor.io/garethdwyer/building-a-discord-bot-with-python-and-repl-it-miblcwejz

You are viewing a single comment. View All
DysonBird (2)

I did everything exactly as it should be, but I still got this error:

Traceback (most recent call last):
File "main.py", line 1, in <module>
from keep_alive import keep_alive
File "/home/runner/Hugo-Dyson/keep_alive.py", line 13
def keep_alive():
^
SyntaxError: invalid syntax

anyone know how to fix this?

GarethDwyer1 (229)

@DysonBird Can you share the rest of your code? it looks like there's something wrong just before line 13.

DysonBird (2)

@GarethDwyer1 Here it is:

from keep_alive import keep_alive
import discord
import os

client = discord.Client()

@client.event
async def on_ready():
print("I'm in")
print(client.user)

@client.event
async def on_message(message):
if message.author != client.user:
await message.channel.send(message.content[::-1])

keep_alive()
token = os.environ.get("DISCORD_BOT_SECRET")
client.run(token)

GarethDwyer1 (229)

@DysonBird The error is in the other file keep_alive.py. Can you share a repl link to the whole project?

GarethDwyer1 (229)

@DysonBird

you need to add a closing bracket after the port number on the line above in keep_alive.py

NitroType (0)

@DysonBird I think that code he showed is outdated. 2 years ago, its outdated. so upgrade, write it newly.