Discord.py: How to fix “event loop is closed”

流过昼夜 提交于 2021-02-09 00:38:14

问题


I am new to programming. I am trying to have my discord bot open up command prompt to confirm it can run, but I am getting this error:

  File "C:\Users\---\AppData\Local\Programs\Python\Python38-32\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "C:\Users\---\AppData\Local\Programs\Python\Python38-32\lib\asyncio\proactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "C:\Users\---\AppData\Local\Programs\Python\Python38-32\lib\asyncio\base_events.py", line 719, in call_soon
    self._check_closed()
  File "C:\Users\---\AppData\Local\Programs\Python\Python38-32\lib\asyncio\base_events.py", line 508, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
[Finished in 0.871s]

Code:

import discord
from discord.ext import commands

client=commands.Bot(command_prefix = '.')

@client.event
async def on_ready():
    print('ok')

client.run(token)

What causes this error, and how can I fix this?

Edit: after some testing, I believe "client.run(token)" is what is causing "event loop is closed", not sure why.


回答1:


You need to go your your Development Panel of the Discord Bot, click on the Bot tab, and there you will find a TOKEN, it says Reveal Token, you just need to click COPY.

Then, on your code you need to establish that token like this.

import discord
from discord.ext import commands

TOKEN = "here paste your token"

client=commands.Bot(command_prefix = '.')

@client.event
async def on_ready():
    print('Connected')

client.run(TOKEN)

This will fix your problem, Enjoy coding!



来源:https://stackoverflow.com/questions/62340248/discord-py-how-to-fix-event-loop-is-closed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!