【问题标题】:Discord.py RuntimeError: There is no current event loop in threadDiscord.py RuntimeError:线程中没有当前事件循环
【发布时间】:2020-06-08 11:54:04
【问题描述】:

这是我的 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)

由于某种原因,它在bot = commands.Bot(command_prefix='!') 出现错误,错误是:

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'.

每次我运行 bot.py 文件时,’Thread-4’ 之后的数字都会增加 1,每次我退出并重新打开文件时,数字都会变为 4,同样的事情会以循环的形式发生。

有人可以帮我解决这个问题吗?

【问题讨论】:

    标签: python discord.py


    【解决方案1】:

    抛开错误,我认为您的问题是命令参数name='ranodm_letter' 中的一个简单拼写错误,您可能打算执行name='random_letter'

    【讨论】:

    • 感谢您的回答,但这并不能解决问题
    猜你喜欢
    • 1970-01-01
    • 2021-02-20
    • 1970-01-01
    • 1970-01-01
    • 2018-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多