-2

I am new in python but, I wanted to make a discord bot. I've already seen some solutions that didn't help me.My problem is that I am getting an error(RuntimeError: Cannot close a running event loop) when i am trying to run this code:

import discord
from discord.ext import commands

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

@client.event
async def on_ready():
    print('Here we go!')
    
client.run('qXfSXVL.......ww4FeCB6H.....Sw6')

P.S. I am using spyder anaconda with python 3.7 and I've tried to install nest_asyncio.

EDIT: I did everything that you said and it keep writing that error.

1 Answers1

0

First you have to install nest_asyncio.

Linux:

pip3 install nest_asyncio

Windows:

pip install nest_asyncio

Then run nest_asyncio code:

import discord
from discord.ext import commands
import nest_asyncio

nest_asyncio.apply()

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

@client.event
async def on_ready():
    print('Here we go!')
    
client.run('qXfSXVL.......ww4FeCB6H.....Sw6')

Same question: How to Fix Runtime Error: Cannot close a running event loop - Python Discord Bot

Zeraye
  • 16
  • 3
  • 2
    Welcome to Stack Overflow. In cases where this question is identical to another question, the recommended course of action is to flag this one as a duplicate instead of adding an answer. – Pranav Hosangadi Dec 01 '20 at 17:18