ArcticFox
ArcticFox

Reputation: 60

Discord.py RuntimeError: There is no current event loop in thread

This is my bot.py:

import os
import random
from discord.ext import commands

TOKEN = 'secret'

bot = commands.Bot(command_prefix='!')
@bot.command(name='ranodm_letter', help='Responds with a random letter')
async def random_fruit(x):
    letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

    response = random.choice(letters)
    await x.send(response)

bot.run(TOKEN)

For some reason it gives error at bot = commands.Bot(command_prefix='!'), the error is:

Traceback (most recent call last):
  File "Documents/bot.py", line 7, in <module>
    bot = commands.Bot(command_prefix='!')
  File "Documents/site-packages/discord/ext/commands/bot.py", line 99, in __init__
    super().__init__(**options)
  File "Documents/site-packages/discord/ext/commands/core.py", line 1031, in __init__
    super().__init__(*args, **kwargs)
  File "Documents/site-packages/discord/client.py", line 206, in __init__
    self.loop = asyncio.get_event_loop() if loop is None else loop
  File "Library/python38/asyncio/events.py", line 639, in get_event_loop
    raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'Thread-4'.

Every time I run the bot.py file the number after ’Thread-4’ increases by one and every time I quit and reopen the file the number becomes 4 and the same thing happens as a loop.

Please can somebody help me with the problem?

Upvotes: 1

Views: 457

Answers (1)

Caio Reis
Caio Reis

Reputation: 56

Leaving the error you got aside, I think your problem is a simple typo in the command parameter name='ranodm_letter', you probably meant to do name='random_letter'.

Upvotes: 1

Related Questions