• <bdo id='IjZ9W'></bdo><ul id='IjZ9W'></ul>
    <legend id='IjZ9W'><style id='IjZ9W'><dir id='IjZ9W'><q id='IjZ9W'></q></dir></style></legend>

    <small id='IjZ9W'></small><noframes id='IjZ9W'>

    1. <i id='IjZ9W'><tr id='IjZ9W'><dt id='IjZ9W'><q id='IjZ9W'><span id='IjZ9W'><b id='IjZ9W'><form id='IjZ9W'><ins id='IjZ9W'></ins><ul id='IjZ9W'></ul><sub id='IjZ9W'></sub></form><legend id='IjZ9W'></legend><bdo id='IjZ9W'><pre id='IjZ9W'><center id='IjZ9W'></center></pre></bdo></b><th id='IjZ9W'></th></span></q></dt></tr></i><div id='IjZ9W'><tfoot id='IjZ9W'></tfoot><dl id='IjZ9W'><fieldset id='IjZ9W'></fieldset></dl></div>

        <tfoot id='IjZ9W'></tfoot>
      1. 如何修复运行时错误:无法关闭正在运行的事件循

        时间:2023-09-09
        <i id='1G7Wa'><tr id='1G7Wa'><dt id='1G7Wa'><q id='1G7Wa'><span id='1G7Wa'><b id='1G7Wa'><form id='1G7Wa'><ins id='1G7Wa'></ins><ul id='1G7Wa'></ul><sub id='1G7Wa'></sub></form><legend id='1G7Wa'></legend><bdo id='1G7Wa'><pre id='1G7Wa'><center id='1G7Wa'></center></pre></bdo></b><th id='1G7Wa'></th></span></q></dt></tr></i><div id='1G7Wa'><tfoot id='1G7Wa'></tfoot><dl id='1G7Wa'><fieldset id='1G7Wa'></fieldset></dl></div>
          <bdo id='1G7Wa'></bdo><ul id='1G7Wa'></ul>
        • <tfoot id='1G7Wa'></tfoot>

                <tbody id='1G7Wa'></tbody>
                1. <legend id='1G7Wa'><style id='1G7Wa'><dir id='1G7Wa'><q id='1G7Wa'></q></dir></style></legend>

                  <small id='1G7Wa'></small><noframes id='1G7Wa'>

                  本文介绍了如何修复运行时错误:无法关闭正在运行的事件循环 - Python Discord Bot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试使用 Python 创建一个 Discord 机器人,但是每当我在这里运行示例代码时:

                  I am trying to create a Discord bot with Python, however whenever I run the sample code here:

                  import discord
                  
                  client = discord.Client()
                  
                  @client.event
                  async def on_message(message):
                      # we do not want the bot to reply to itself
                      if message.author == client.user:
                          return
                  
                      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('tokenhere')
                  

                  返回错误:

                  Traceback (most recent call last):
                  
                    File "<ipython-input-6-ea5a13e5703d>", line 1, in <module>
                      runfile('C:/Users/User/Pictures/rito_bot.py', wdir='C:/Users/User/Pictures')
                  
                    File "C:UsersUserAnaconda3libsite-packagesspyder_kernelscustomizespydercustomize.py", line 703, in runfile
                      execfile(filename, namespace)
                  
                    File "C:UsersUserAnaconda3libsite-packagesspyder_kernelscustomizespydercustomize.py", line 108, in execfile
                      exec(compile(f.read(), filename, 'exec'), namespace)
                  
                    File "C:/Users/User/Pictures/rito_bot.py", line 22, in <module>
                      client.run('token')
                  
                    File "C:UsersUserAnaconda3libsite-packagesdiscordclient.py", line 595, in run
                      _cleanup_loop(loop)
                  
                    File "C:UsersUserAnaconda3libsite-packagesdiscordclient.py", line 97, in _cleanup_loop
                      loop.close()
                  
                    File "C:UsersUserAnaconda3libasyncioselector_events.py", line 94, in close
                      raise RuntimeError("Cannot close a running event loop")
                  
                  RuntimeError: Cannot close a running event loop 
                  

                  其他每一行似乎都运行得很好,但是如果没有最后一行,它就无法连接到服务器,这使得它毫无用处.

                  Every other line seems to run just fine, but without the last line it doesn't connect to the server, which makes it useless.

                  注意:我在这里看到了问题,但是 OP 的解决方案似乎不适用于我的情况.

                  Note: I have seen the question here, however OP's solution doesn't seem applicable to my situation.

                  推荐答案

                  (这里是 Spyder 维护者)要在我们的控制台中运行异步代码,您首先需要安装 nest_asyncio 包,然后在运行任何代码之前调用它,如其自述文件中所述.

                  (Spyder maintainer here) To run async code in our consoles you first need to install the nest_asyncio package and then call it before running any of your code as described on its Readme.

                  这篇关于如何修复运行时错误:无法关闭正在运行的事件循环 - Python Discord Bot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何检查用户是否在不和谐中具有特定角色 下一篇:如何获取对 discord.py 中的消息做出反应的成员列

                  相关文章

                  最新文章

                  <i id='F6fNv'><tr id='F6fNv'><dt id='F6fNv'><q id='F6fNv'><span id='F6fNv'><b id='F6fNv'><form id='F6fNv'><ins id='F6fNv'></ins><ul id='F6fNv'></ul><sub id='F6fNv'></sub></form><legend id='F6fNv'></legend><bdo id='F6fNv'><pre id='F6fNv'><center id='F6fNv'></center></pre></bdo></b><th id='F6fNv'></th></span></q></dt></tr></i><div id='F6fNv'><tfoot id='F6fNv'></tfoot><dl id='F6fNv'><fieldset id='F6fNv'></fieldset></dl></div>

                    • <bdo id='F6fNv'></bdo><ul id='F6fNv'></ul>
                    <legend id='F6fNv'><style id='F6fNv'><dir id='F6fNv'><q id='F6fNv'></q></dir></style></legend><tfoot id='F6fNv'></tfoot>

                    <small id='F6fNv'></small><noframes id='F6fNv'>