-
Hi! I know basically nothing about coding and for the last three hours i tried to make a discord bot. import discord
client = discord.Client()
@client.event
def on_ready():
print('We have logged in as {0.user}'.format(client))
@client.event
def on_message(message):
if message.author == client.user:
return
if message.content.startswith('$hello'):
message.channel.send('Hello!')
client.run('token') this is what i wrote but it always gives me an error.
i dont know how to fix it. please help. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
There are a few issues here.
It's generally recommended to familiarise yourself with Python before starting to work on a Discord bot. Otherwise you'll end up struggling a lot when playing around with the library. I am unsure where your SyntaxError is -- it looks syntactically valid. There might have been issue somewhere else, either with a stray character or potentially a transcribing issue. I'm not entirely sure. |
Beta Was this translation helpful? Give feedback.
-
You probably did this but in case not |
Beta Was this translation helpful? Give feedback.
There are a few issues here.
async def
rather thandef
. This should have errored earlier.message.channel.send
is a coroutine, so it needsawait
before it.It's generally recommended to familiarise yourself with Python before starting to work on a Discord bot. Otherwise you'll end up struggling a lot when playing around with the library.
I am unsure where your SyntaxError is -- it looks syntactically valid. There might have been issue somewhere else, either with a stray character or potentially a transcribing issue. I'm not entirely sure.