【发布时间】: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