在 visual studio 中添加 discord.py 文件时出现语法错误 "unexpected token"

I'm getting a syntax error saying "unexpected token" when adding the discord.py file in visual studio

所以我通常用 C++ 编写代码,这是我第一次使用 python。我正在尝试编写 Discord 机器人的代码,并且正在学习教程。它说要将这一行添加到我的代码的顶部

py -3 -m pip install -U discord.py

我在 pip 下遇到四个语法错误,discord.py 都说“意外的标记”。我查看了多个其他教程以及我正在关注的教程,其中 none 提到了这一点。我使用的是 python 版本 3.7.8,所以我很确定这不是问题所在。我尝试切换到 Repl.it IDE 并遵循告诉我使用

的不同教程

import discord

由于我不太了解的原因,这没有用。这就是我的代码的样子

py -3 -m pip install -U discord.py

client = discord.Client()

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))

@client.event
async def on_message(message):
    if message.author == client.user:
        return

    if message.content.startswith('$hello'):
        await message.channel.send('Hello!')

client.run(My bot's token)

我不知道我做错了什么。

确保您已安装 pip,您可以在终端中进行安装。如果您在 Unix/macOS,请尝试 python -m pip install -U pip。如果您在 Windows,请尝试 py -m pip install -U pip。然后,在代码的开头添加:

try:
    import discord
except ImportError:
    import pip
    pip.main(['install', 'discord'])
    import discord