How to fix "SyntaxError: invalid syntax" in discord bot

Viewed 3869

I am new at programming. I have been trying to make a discord bot, but every time I try to launch it it fails with SyntaxError: invalid syntax.

Code:

import discord.py
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio

Client = discord.Client()
bot_prefix= "^"
client = commands.Bot(command_prefix=bot_prefix)

@client.event
async def on_ready():
    print("Bot Online!")
    print("Name: {}".format(client.user.name))
    print("ID: {}".format(client.user.id))

@client.command(pass_context=True)
async def ping(ctx):
    await client.say("Pong!")

client.run("ID")

Error:

C:\Users\Vanias>"C:\Users\Vanias\Desktop\MemerBoy\Test 3 bot 3.py"
Traceback (most recent call last):
  File "C:\Users\Vanias\Desktop\MemerBoy\Test 3 bot 3.py", line 1, in <module>
    import discord.py
  File "C:\Users\Vanias\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\__init__.py", line 20, in <module>
    from .client import Client, AppInfo, ChannelPermissions
  File "C:\Users\Vanias\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\client.py", line 38, in <module>
    from .state import ConnectionState
  File "C:\Users\Vanias\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\state.py", line 36, in <module>
    from . import utils, compat
  File "C:\Users\Vanias\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\compat.py", line 32
    create_task = asyncio.async
                              ^
SyntaxError: invalid syntax
2 Answers

you have to put your bots token in client.run('your bots token here') not the id

you can google how to get your bots token

also check this basic bot example

try using this import pip install -U discord.py sorry for the late answer lol

Related