Question

How do I code a Discord Bot in Python on an Iphone or Chromebook?

**I am trying to code a bot for discord, but I do not have a laptop or an android. The chromebook I have is a school owned one, so things like downloads and developer mode are blocked. I can’t get the linux demo either. If it is not possible to code on this through web, then I do have an Iphone, which I have been told is impossible to code on… I’m not worried about how long the code takes to develop, I just want to be able to code it without any laptop.

Additionally, all attempts to use a code given with this website: https://github.com/Rapptz/discord.py/tree/async

I enter this example:

import discord
import asyncio

client = discord.Client()

@client.event
async def on_ready():
    print('Logged in as')
    print(client.user.name)
    print(client.user.id)
    print('------')

@client.event
async def on_message(message):
    if message.content.startswith('!test'):
        counter = 0
        tmp = await client.send_message(message.channel, 'Calculating messages...')
        async for log in client.logs_from(message.channel, limit=100):
            if log.author == message.author:
                counter += 1

        await client.edit_message(tmp, 'You have {} messages.'.format(counter))
    elif message.content.startswith('!sleep'):
        await asyncio.sleep(5)
        await client.send_message(message.channel, 'Done sleeping')

client.run('token')

but it gives me a syntax error like this:

Unknown Error.
  File "<stdin>", line 7
    async def on_ready():
        ^
SyntaxError: invalid syntax
Unknown Error.

This is insanely frustrating… can someone assist?

(i am using https://thumbsdb.herokuapp.com/python/?state={"folderId":"0AIiLka239X73Uk9PVA","action":"create","userId":"117443184978319349054"} and https://www.onlinegdb.com/ to enter and run code)

Show comments

Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Matt Cowley
Site Moderator
Site Moderator badge
November 1, 2019
Accepted Answer

Hi there @eX2ii2t,

This error normally means that you’re using a version of Python that does not support async syntax. This is normally Python 2.x

Looking at the website you linked, it does indeed appear that it is using Python 2, which is why your program is not working.

Loading Python library.......Ready!
>>> import sys
>>> sys.version
'2.7.4 (default, May 10 2013, 01:23:53) \n[GCC 4.2.1 Compatible Clang 3.2 (tags/RELEASE_32/final)]'
>>>

You’ll need to find an online editor that supports Python 3.5+, as documented in the GitHub repository for this library: https://github.com/Rapptz/discord.py

(As a side note, the async branch of the library is no longer maintained and you should use the version of the library contained within master, which is available on PyPi.org)

Hope that helps! - Matt.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel