0

I try to follow a tutorial on how to host a discord bot with discord.py. I did everything correctly but pyflakes shows a syntax error. Do You know why?

I've got two files: main.py and keep_alive.py. This is main.py:

import os
import discord
from keep_alive import keep_alive
from discord.ext import commands

TOKEN = os.environ('TOKEN')
client = commands.Bot(command_prefix='!')

async def on_ready():
  await client.change_presence(activity=discord.ActivityType.listenting('to the server!', status=discord.Status.online)

keep_alive.keep_alive()
client.run(TOKEN, bot=True, reconnect=True)

And this is keep_alive.py:

from flask import Flask
from threading import Thread

app = Flask('')

@app.route('/')
def main():
    return "<h1>Your bot is alive!</h1>"

def run():
    app.run(host="0.0.0.0", port=8080)

def keep_alive():
    server = Thread(target=run)
    server.start()`

When I run the program, I get this error:

  File "main.py", line 12
    keep_alive.keep_alive()
    ^
SyntaxError: invalid syntax
 
Sneezy_HD
  • 55
  • 6

1 Answers1

0

Your code have major faults in your code. First of all you are using replit in which env tokens are accessed using os.environ["Key_Name"]. Then you are importing keep_alive from keep_alive and only need to call it using keep_alive(). Then you are missing a closing parentheses ) in the change_presence. Also, Do not change presence in the on_ready event (Your bot may disconnect even if it doesn't for the first few times.) instead change the activity in the bot constructor.

BotClient = commands.Bot(command_prefix=prefixes, intents=discord.Intents.all(), help_command=None, activity=discord.Activity(type=discord.ActivityType.listening, name="Spotify"))
Ash
  • 1
  • 2