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

    <small id='9bGNN'></small><noframes id='9bGNN'>

        • <bdo id='9bGNN'></bdo><ul id='9bGNN'></ul>

        运行我的 discord.py 机器人时在 client.run('token

        时间:2023-10-11
        <i id='Tvd2C'><tr id='Tvd2C'><dt id='Tvd2C'><q id='Tvd2C'><span id='Tvd2C'><b id='Tvd2C'><form id='Tvd2C'><ins id='Tvd2C'></ins><ul id='Tvd2C'></ul><sub id='Tvd2C'></sub></form><legend id='Tvd2C'></legend><bdo id='Tvd2C'><pre id='Tvd2C'><center id='Tvd2C'></center></pre></bdo></b><th id='Tvd2C'></th></span></q></dt></tr></i><div id='Tvd2C'><tfoot id='Tvd2C'></tfoot><dl id='Tvd2C'><fieldset id='Tvd2C'></fieldset></dl></div>
        <legend id='Tvd2C'><style id='Tvd2C'><dir id='Tvd2C'><q id='Tvd2C'></q></dir></style></legend>
          <bdo id='Tvd2C'></bdo><ul id='Tvd2C'></ul>

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

        • <tfoot id='Tvd2C'></tfoot>

                <tbody id='Tvd2C'></tbody>
                • 本文介绍了运行我的 discord.py 机器人时在 client.run('token') 收到运行时错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试用 Python 制作一个 Discord 机器人,它根据您所在的班级(在我的学校)为您提供 Discord 服务器上的角色.我刚刚开始,但每当我尝试运行它时都会收到错误消息(我在 Python 3 Notebook 中的 Google Colab 中运行它).这是我的代码:

                  I am attempting to make a Discord bot in Python that gives you a role on a Discord server based upon what class you are in (at my school). I have just started, but I am receiving an error whenever I attempt to run it (I run it in Google Colab in a Python 3 Notebook). Here is my code:

                  from datetime import date
                  import time
                  import discord
                  
                  client = discord.Client()
                  
                  @client.event
                  async def on_ready():
                      print('We have logged in as {0.user}'.format(client))
                  
                  client.run('my token (not shown for obvious reasons)')
                  
                  starttime=time.time()
                  while True:
                    currentTime = time.strftime("%H:%M")
                    print("new minute")
                    if 0 <= date(int(time.strftime("%Y")), int(time.strftime("%m")), int(time.strftime("%d"))).weekday() <= 4:
                      if currentTime == "13:41":
                        print("First hour has started!")
                      elif currentTime == "13:45":
                        print("First hour has started! (hs)")
                      elif currentTime == "14:30":
                        print("First hour has ended at high school.")
                    time.sleep(60.0 - ((time.time() - starttime) % 60.0))
                  
                  

                  当我运行它时,它会提示我这个错误:

                  When I run it, it presents me with this error:

                  ---------------------------------------------------------------------------
                  RuntimeError                              Traceback (most recent call last)
                  <ipython-input-5-d40f2b4200ae> in <module>()
                        9     print('We have logged in as {0.user}'.format(client))
                       10 
                  ---> 11 client.run('my token')
                       12 
                       13 starttime=time.time()
                  
                  2 frames
                  /usr/local/lib/python3.6/dist-packages/discord/client.py in run(self, *args, **kwargs)
                      570 
                      571         try:
                  --> 572             loop.add_signal_handler(signal.SIGINT, lambda: loop.stop())
                      573             loop.add_signal_handler(signal.SIGTERM, lambda: loop.stop())
                      574         except NotImplementedError:
                  
                  /usr/lib/python3.6/asyncio/unix_events.py in add_signal_handler(self, sig, callback, *args)
                       92                             "with add_signal_handler()")
                       93         self._check_signal(sig)
                  ---> 94         self._check_closed()
                       95         try:
                       96             # set_wakeup_fd() raises ValueError if this is not the
                  
                  /usr/lib/python3.6/asyncio/base_events.py in _check_closed(self)
                      375     def _check_closed(self):
                      376         if self._closed:
                  --> 377             raise RuntimeError('Event loop is closed')
                      378 
                      379     def _asyncgen_finalizer_hook(self, agen):
                  
                  RuntimeError: Event loop is closed
                  

                  如果我将 client.run 命令放在底部,程序永远不会到达它,因为循环会阻止它到达命令.

                  If I put the client.run command at the bottom, the program never reaches it because the loop prevents it from reaching the command.

                  我错过了什么吗?我不知道问题出在哪里.非常感谢帮助.

                  Am I missing something? I do not know where the problem is. Would appreciate help.

                  推荐答案

                  基本上,如果你想在 google colab 上运行 discord 机器人,你需要做各种黑客攻击.这里我使用 discord.ext python 库,执行这个,但是会阻塞,并阻止你执行任何其他单元格.

                  Basically there are various hacks you need to do if you want to run a discord bot on google colab. Here I use discord.ext python library, executing this, however will be blocking, and prevent you from executing any other cells.

                  !pip install discord.py
                  import nest_asyncio
                  nest_asyncio.apply()
                   
                  import asyncio
                  await = lambda x: asyncio.get_event_loop().run_until_complete(x)
                  async def init(what, token):
                      await what(token)
                  import discord
                  from discord.ext import commands
                  bot = commands.Bot(command_prefix="")
                  async def start():
                      await bot.wait_until_ready()
                      print("ready")
                      await bot.get_channel(channelID).send("hi")
                  
                  bot.loop.create_task(start())
                  
                  TOKEN = ""   #@param {type: "string"}
                  
                  

                  这篇关于运行我的 discord.py 机器人时在 client.run('token') 收到运行时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在 discord.py 中获取所有成员列表? 下一篇:Discord.py:如何修复“事件循环已关闭";

                  相关文章

                  最新文章

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

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

                      <legend id='Qh9CD'><style id='Qh9CD'><dir id='Qh9CD'><q id='Qh9CD'></q></dir></style></legend>
                    1. <tfoot id='Qh9CD'></tfoot>