1

I tried a few different codes but they all seem to be giving me the same error.

import discord

client = discord.Client()
client.run("TheBotTokenzzzInQuotes")

And it's giving me this error

File "<ipython-input-1-1f31c2ad1160>", line 1, in <module>
    runfile('C:/Users/Lenovo/Desktop/bot.py', wdir='C:/Users/Lenovo/Desktop')

      File "C:\Users\Lenovo\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
        execfile(filename, namespace)

      File "C:\Users\Lenovo\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
        exec(compile(f.read(), filename, 'exec'), namespace)

      File "C:/Users/Lenovo/Desktop/bot.py", line 4, in <module>
        client.run("token")

      File "C:\Users\Lenovo\Anaconda3\lib\site-packages\discord\client.py", line 637, in run
        _cleanup_loop(loop)

      File "C:\Users\Lenovo\Anaconda3\lib\site-packages\discord\client.py", line 97, in _cleanup_loop
        loop.close()

      File "C:\Users\Lenovo\Anaconda3\lib\asyncio\selector_events.py", line 83, in close
        raise RuntimeError("Cannot close a running event loop")

    RuntimeError: Cannot close a running event loop
4
  • Which version of Python are you running? Commented Apr 19, 2020 at 19:49
  • Our IPython consoles already run an asyncio event loop, so I think you need to install and run nest-asyncio before running your code. Commented Apr 19, 2020 at 20:50
  • Im using python 3.7.4 running it on spyder, anaconda. I installed and ran it but the code still isnt working Commented Apr 20, 2020 at 3:59
  • 1
    I have the same problem directly after importing and applying nest_asyncio. Before that I got a different runtime error, that one about the loop already running. I found an answer that said Jupyter Notebook runs it's own event loop, and 2 cannot run together until nest_asyncio is installed. So I installed it, and now sit with a different but somehow clearer error. I still have no clue, so I am pinning a bounty on this question. Commented Jul 19, 2020 at 14:28

1 Answer 1

4
+50

I have my own discord bot that I run, and the client variable for mine doesn't look anything like that if I'm being honest.

If you are not using "Discord.py Rewrite", that could be a possible reason for a failure.

Another possible reason(although very unlikely) is that you do not have aiohttp installed(which is the dependency asyncio needs for Discord.py Rewrite), you can install it by using the following command:

pip install aiohttp

If you would like an example bot to look at, I have listed one below that is directly from the developer of discord.py Rewrite(the version that is currently supported for python).

https://github.com/Rapptz/discord.py/blob/master/examples/basic_bot.py

If you were wondering what the beginning of my code looked like, I have it below this:

import discord
from discord.ext import commands
from discord.utils import get

client = commands.Bot(command_prefix = '>')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.