Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python 3.9 discord.py asyncio.async错误_Python_Python 3.x_Pycharm_Discord.py - Fatal编程技术网

python 3.9 discord.py asyncio.async错误

python 3.9 discord.py asyncio.async错误,python,python-3.x,pycharm,discord.py,Python,Python 3.x,Pycharm,Discord.py,这个问题涉及由asyncio引起的discord.py错误,但是任何关于创建discord bot的建议都是非常受欢迎的。我非常愿意阅读文档以充分理解回复,并将继续阅读提供的文章 问题: Has anyone had success with discord bots in python 3.9? Is something wrong with my script? Is async a keyword in python 3.9? If so, how can i mo

这个问题涉及由asyncio引起的discord.py错误,但是任何关于创建discord bot的建议都是非常受欢迎的。我非常愿意阅读文档以充分理解回复,并将继续阅读提供的文章

问题:

    Has anyone had success with discord bots in python 3.9?
    Is something wrong with my script?
    Is async a keyword in python 3.9? If so, how can i modify my program to solve this problem?
    How can I fix this issue without downgrading to python 3.6? Is that the only way?
    Why does pip install discord not work? What are wheels? I do not want to install C++ build tools.
    Would it be easier to program a bot in C++ or JS? I don't know any JS but i am familiar with C++.
我正试图在Python3.9中创建一个简单的discord机器人。我是python新手,一直在使用pycharm编写脚本。我在尝试运行脚本时发现一个错误。此处提供的脚本:

import discord

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 token')
Traceback (most recent call last):
  File "C:\Users\User\py_projects\discord\scrambot_main.py", line 2, in <module>
    import discord
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\__init__.py", line 20, in <module>
    from .client import Client, AppInfo, ChannelPermissions
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 38, in <module>
    from .state import ConnectionState
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\state.py", line 36, in <module>
    from . import utils, compat
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\compat.py", line 32
    create_task = asyncio.async
                          ^
SyntaxError: invalid syntax
此处提供的错误:

import discord

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 token')
Traceback (most recent call last):
  File "C:\Users\User\py_projects\discord\scrambot_main.py", line 2, in <module>
    import discord
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\__init__.py", line 20, in <module>
    from .client import Client, AppInfo, ChannelPermissions
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 38, in <module>
    from .state import ConnectionState
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\state.py", line 36, in <module>
    from . import utils, compat
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\compat.py", line 32
    create_task = asyncio.async
                          ^
SyntaxError: invalid syntax
问题:

    Has anyone had success with discord bots in python 3.9?
    Is something wrong with my script?
    Is async a keyword in python 3.9? If so, how can i modify my program to solve this problem?
    How can I fix this issue without downgrading to python 3.6? Is that the only way?
    Why does pip install discord not work? What are wheels? I do not want to install C++ build tools.
    Would it be easier to program a bot in C++ or JS? I don't know any JS but i am familiar with C++.
在此问题上的任何帮助都将不胜感激。此外,由于这是我的第一篇堆栈溢出文章,请随时告诉我,如果我可以做的更好,问这个问题。如果有什么我可以提供,以帮助您优秀的开发人员谁愿意花他们的时间解决像这一个noob问题,请让我知道

此外,如果愿意并且能够,请提供一些编写discord机器人程序的技巧。这是一个小型管理机器人,用于测试和发展我的python技能。与人的互动是重点,而不是任何形式的自动化,尽管我确实想尝试尽可能多的想法

C:\Users\User>pip3 install discord
Collecting discord
  Using cached discord-1.0.1-py3-none-any.whl (1.1 kB)
Collecting discord.py>=1.0.1
  Using cached discord.py-1.5.1-py3-none-any.whl (701 kB)
Processing c:\users\user\appdata\local\pip\cache\wheels\b6\9c\bd\6b99bc6ec9dab11f3756d31fb8506d3ecf07aea58b6201f539\aiohttp-3.6.3-py3-none-any.whl
Collecting attrs>=17.3.0
  Using cached attrs-20.2.0-py2.py3-none-any.whl (48 kB)
Requirement already satisfied: chardet<4.0,>=2.0 in c:\users\user\appdata\local\programs\python\python39\lib\site-packages (from aiohttp<3.7.0,>=3.6.0->discord.py>=1.0.1->discord) (3.0.4)
Collecting yarl<1.6.0,>=1.0
  Using cached yarl-1.5.1.tar.gz (173 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Collecting multidict<5.0,>=4.5
  Using cached multidict-4.7.6.tar.gz (50 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Requirement already satisfied: async-timeout<4.0,>=3.0 in c:\users\user\appdata\local\programs\python\python39\lib\site-packages (from aiohttp<3.7.0,>=3.6.0->discord.py>=1.0.1->discord) (3.0.1)
Collecting idna>=2.0
  Using cached idna-2.10-py2.py3-none-any.whl (58 kB)
Building wheels for collected packages: yarl, multidict
  Building wheel for yarl (PEP 517) ... error
  ERROR: Command errored out with exit status 1:
   command: 'c:\users\user\appdata\local\programs\python\python39\python.exe' 'c:\users\user\appdata\local\programs\python\python39\lib\site-packages\pip\_vendor\pep517\_in_process.py' build_wheel 'C:\Users\User\AppData\Local\Temp\tmpib94rz6b'
       cwd: C:\Users\User\AppData\Local\Temp\pip-install-rrtk0pij\yarl
  Complete output (35 lines):
  **********************
  * Accellerated build *
  **********************
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build\lib.win-amd64-3.9
  creating build\lib.win-amd64-3.9\yarl
  copying yarl\_quoting.py -> build\lib.win-amd64-3.9\yarl
  copying yarl\_quoting_py.py -> build\lib.win-amd64-3.9\yarl
  copying yarl\_url.py -> build\lib.win-amd64-3.9\yarl
  copying yarl\__init__.py -> build\lib.win-amd64-3.9\yarl
  running egg_info
  writing yarl.egg-info\PKG-INFO
  writing dependency_links to yarl.egg-info\dependency_links.txt
  writing requirements to yarl.egg-info\requires.txt
  writing top-level names to yarl.egg-info\top_level.txt
  reading manifest file 'yarl.egg-info\SOURCES.txt'
  reading manifest template 'MANIFEST.in'
  warning: no previously-included files matching '*.pyc' found anywhere in distribution
  warning: no previously-included files matching '*.cache' found anywhere in distribution
  warning: no previously-included files found matching 'yarl\*.html'
  warning: no previously-included files found matching 'yarl\*.so'
  warning: no previously-included files found matching 'yarl\*.pyd'
  no previously-included directories found matching 'docs\_build'
  writing manifest file 'yarl.egg-info\SOURCES.txt'
  copying yarl\__init__.pyi -> build\lib.win-amd64-3.9\yarl
  copying yarl\_quoting_c.c -> build\lib.win-amd64-3.9\yarl
  copying yarl\_quoting_c.pyi -> build\lib.win-amd64-3.9\yarl
  copying yarl\_quoting_c.pyx -> build\lib.win-amd64-3.9\yarl
  copying yarl\py.typed -> build\lib.win-amd64-3.9\yarl
  running build_ext
  building 'yarl._quoting_c' extension
  error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
  ----------------------------------------
  ERROR: Failed building wheel for yarl
  Building wheel for multidict (PEP 517) ... error
  ERROR: Command errored out with exit status 1:
   command: 'c:\users\user\appdata\local\programs\python\python39\python.exe' 'c:\users\user\appdata\local\programs\python\python39\lib\site-packages\pip\_vendor\pep517\_in_process.py' build_wheel 'C:\Users\User\AppData\Local\Temp\tmp_yeznrct'
       cwd: C:\Users\User\AppData\Local\Temp\pip-install-rrtk0pij\multidict
  Complete output (40 lines):
  **********************
  * Accellerated build *
  **********************
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build\lib.win-amd64-3.9
  creating build\lib.win-amd64-3.9\multidict
  copying multidict\_abc.py -> build\lib.win-amd64-3.9\multidict
  copying multidict\_compat.py -> build\lib.win-amd64-3.9\multidict
  copying multidict\_multidict_base.py -> build\lib.win-amd64-3.9\multidict
  copying multidict\_multidict_py.py -> build\lib.win-amd64-3.9\multidict
  copying multidict\__init__.py -> build\lib.win-amd64-3.9\multidict
  running egg_info
  writing multidict.egg-info\PKG-INFO
  writing dependency_links to multidict.egg-info\dependency_links.txt
  writing top-level names to multidict.egg-info\top_level.txt
  reading manifest file 'multidict.egg-info\SOURCES.txt'
  reading manifest template 'MANIFEST.in'
  warning: no previously-included files matching '*.pyc' found anywhere in distribution
  warning: no previously-included files found matching 'multidict\_multidict.html'
  warning: no previously-included files found matching 'multidict\*.so'
  warning: no previously-included files found matching 'multidict\*.pyd'
  warning: no previously-included files found matching 'multidict\*.pyd'
  no previously-included directories found matching 'docs\_build'
  writing manifest file 'multidict.egg-info\SOURCES.txt'
  copying multidict\__init__.pyi -> build\lib.win-amd64-3.9\multidict
  copying multidict\_multidict.c -> build\lib.win-amd64-3.9\multidict
  copying multidict\py.typed -> build\lib.win-amd64-3.9\multidict
  creating build\lib.win-amd64-3.9\multidict\_multilib
  copying multidict\_multilib\defs.h -> build\lib.win-amd64-3.9\multidict\_multilib
  copying multidict\_multilib\dict.h -> build\lib.win-amd64-3.9\multidict\_multilib
  copying multidict\_multilib\istr.h -> build\lib.win-amd64-3.9\multidict\_multilib
  copying multidict\_multilib\iter.h -> build\lib.win-amd64-3.9\multidict\_multilib
  copying multidict\_multilib\pair_list.h -> build\lib.win-amd64-3.9\multidict\_multilib
  copying multidict\_multilib\views.h -> build\lib.win-amd64-3.9\multidict\_multilib
  running build_ext
  building 'multidict._multidict' extension
  error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
  ----------------------------------------
  ERROR: Failed building wheel for multidict
Failed to build yarl multidict
ERROR: Could not build wheels for yarl, multidict which use PEP 517 and cannot be installed directly
编辑: 包括python解释器设置。

在打开一个新的venv项目并在其中安装discord.py时也有问题。与上面相同的车轮错误,在下图中提供了错误和其他相关窗口。还不确定将脚本文件放在何处或如何进行运行配置。

您是否正在使用虚拟环境以及PyCharm python解释器设置中显示的版本(添加到您的帖子中)。您的代码在虚拟环境设置为Python3.9并包discord.py版本1,5,1的情况下成功地为我工作。@davestwhere我在创建时尝试使用venv选项设置重复项目。我看不到任何地方可以放我的代码。我应该把我的脚本放在哪个目录?看起来像是在Windows上,它希望你有MSC++版本14或更大的版本,我是非Windows,所以不能提供任何输入,但是尝试根据错误信息修复问题。如果查看“最新版本”列,您将看到一个箭头,指示discord.py升级到1.5.1-如果突出显示该行并单击右侧的箭头,它应该为您升级(当然,您需要修复Windows问题)。您的代码工作区在右下角的状态栏中显示venv,并且看起来是正确的。您是否使用虚拟环境以及PyCharm python解释器设置中显示的版本(添加到帖子中)。您的代码在虚拟环境设置为Python3.9并包discord.py版本1,5,1的情况下成功地为我工作。@davestwhere我在创建时尝试使用venv选项设置重复项目。我看不到任何地方可以放我的代码。我应该把我的脚本放在哪个目录?看起来像是在Windows上,它希望你有MSC++版本14或更大的版本,我是非Windows,所以不能提供任何输入,但是尝试根据错误信息修复问题。如果查看“最新版本”列,您将看到一个箭头,指示discord.py升级到1.5.1-如果突出显示该行并单击右侧的箭头,它应该为您升级(当然,您需要修复Windows问题)。您的代码工作区在右下角的状态栏中显示venv,并且看起来是正确的。