你好,我写了一个使用齿轮的机器人,但出现此错误:
Traceback (most recent call last):
File "MainBot.py", line 42, in <module>
bot.load_extension('Cog.Ship')
File "C:\Python38\lib\site-packages\discord\ext\commands\bot.py", line 660, in load_extension
spec = importlib.util.find_spec(name)
File "C:\Python38\lib\importlib\util.py", line 94, in find_spec
parent = __import__(parent_name, fromlist=['__path__'])
ModuleNotFoundError: No module named 'Cog'
这是我的主文件:
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix='al_', case_insensitive=True)
@bot.event
async def on_connect():
print('Bot Online!')
bot.load_extension('Cog.Ship')
bot.run("No Token for you")
这是我的齿轮文件:
from discord.ext import commands
import discord
import random
class Ship(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command()
async def ship(self, message):
line = message.content
name = line.split(' ')[1]
name2 = line.split(' ')[2]
labels = {0: "Awful", 1: "Bad", 2 : "Pretty Low", 3 : "Not Great", 4 : "Not Too Bad", 5 : "Barely", 6 : "Not Bad", 7 : "Pretty Good", 8 : "Great", 9: "Amazing", 10 : "**PERFECT**"}
number = random.randint(0,100)
label = labels[int(number/10)]
await message.channel.send(f":heartpulse:**MATCHMAKING**:heartpulse:\n:small_red_triangle_down:`{name}`\n:small_red_triangle:`{name2}`\n**{number}%** **{label}** :heart:")
def setup(bot):
bot.add_cog(Ship(bot))
我能够将其写在一个文件中,但是您可能知道,齿轮会使我的代码更加井井有条
如果“ Ship.py”所在的文件夹称为“ Cog”,那将是正确的