Python 无效语法(Py 3.6)

Python 无效语法(Py 3.6),python,python-3.x,Python,Python 3.x,我对编码相当陌生,正在尝试创建一个不和谐的机器人。我不知道为什么这个代码没有运行,虽然终端说“如果”是无效的,但从以前简单编码的经验来看,它一直是有效的。我会感谢任何能帮忙的人 #Python 3.6 import discord from discord.ext import commands from discord.ext.commands import Bot import asyncio bot = commands.Bot(commands_prefix='#') client

我对编码相当陌生,正在尝试创建一个不和谐的机器人。我不知道为什么这个代码没有运行,虽然终端说“如果”是无效的,但从以前简单编码的经验来看,它一直是有效的。我会感谢任何能帮忙的人

#Python 3.6
import discord
from discord.ext import commands
from discord.ext.commands import Bot
import asyncio

bot = commands.Bot(commands_prefix='#')

client = discord.Client()

@client.event
if message.content.startswith('!hello'):
    msg = 'Hello {0.author.mention}'.format(message)
    await client.send_message(message.channel, msg)

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

client.run('NTA4NjE2MjkwNzE4NzExODA4.DsEiuA.gmMBw3TUxLZJ5puM1Snco_DZWKU'
)

@client.event
是一个函数装饰器(因为
@
)。它后面必须有一个函数定义,修饰符将应用于该函数定义。

不要将代码作为图像发布,而要将其内联到问题中。将代码作为问题的一部分发布,而不是作为问题的一部分发布image@client.event异步def on_消息(消息):if message.author==client.user:return if message.content.startswith(“!hello”):msg='hello{0.author.notice}'。格式(消息)等待客户端。发送消息(message.channel,msg)