3

So, I'm trying to write a bot for a discord server, using discord.py as an API wrapper. I'm trying to use my Raspberry Pi 2 B as a server to run it. I have jessie and python 3.4 installed on the device, as well as some modules for python. The imported modules in my code are discord, asyncio, and datetime. However, when I try to run my bot, which works perfectly on my mac, I get this error message:

File "BotTest.py", line 8
    async def on_ready():
        ^

SyntaxError: invalid syntax

For reference: this is a sample of the code I'm using:

import discord
import asyncio
import datetime

bot = discord.Client()

@bot.event
async def on_ready():
    print('Logged in as')
    print(bot.user.name, bot.user)
    print(bot.user.id)
    print([c.name for c in bot.get_all_channels()])
    print('------')

bot.run('Bot-User-Token')

The 'Bot-User-Token' is, of course, replaced by the actual user token in the full code. The only other part of the code is a function defined with 'async def on_message(message):', so it would be affected by the same issue.

1

3 Answers 3

6

I believe async and await are for python 3.5, I think you'll need to use the @asyncio.coroutine decorator for async def and yield from for await in python 3.4

-2

from version 3.4 asycn and await are reserved keywords

like the error in below image

enter image description here

copy the link up to directory/folder name( not include init.py) you will get a list of .py files enter image description here

rename async file to _async or asynch or anything u want as async is now a reserved keyword with us from version 3.4

once renamed than open check in all files where we have import async modify the new name every where

and enjoy

1
  • It looks like the OP intended to use the reserved syntax in order to use async functions; in this case there is no clashing module as in your images. The accepted answer has the actual issue and solution here.
    – Aurora0001
    Aug 21, 2018 at 17:39
-2

You could just do python3 <yourbot>.py since it uses python3

edit: for this to work you need to do make sure python3 has discord.py by using pip3 install discord-rewrite and your code would have to be written with discord rewrite modules.

1
  • 2
    As tobyd's answer points out, async and await aren't supported until Python 3.5, but the question says that Python 3.4 is installed. Running python3 <yourbot>.py will just run the Python 3.4 version which doesn't work, unfortunately. Perhaps you could explain how to make sure you have Python 3.5 which will work?
    – Aurora0001
    Aug 31, 2018 at 9:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.