首页 > 解决方案 > Atom 编辑器和 Discord 与 Python,出现错误 discord.ext.commands.errors.NoEntryPointError: Extension

问题描述

在主要代码行 15-21

@client.command()
async def unload(ctx, extension):
    client.unload_extension(f'cogs.{extension}')

for filename in os.listdir('./cogs'):
    if filename.endswith('.py'):
        client.load_extension(f'cogs.{filename[:-3]}')

在 Cog 中的 rs9.py 上:下面的第 1-9 行。

import discord
import os
import random
from discord.ext import commands

class rs9(commands.Cog):

    def __init__(self,client):
        self.client=client

我在另一个运行良好的 cog 中为八球命令输入了相同的确切格式。由于某种原因,这个齿轮不断抛出代码:

设置块:

        def setup(client):
            client.add_cog(rs9(client))
Traceback (most recent call last):
  File "C:\Users\Mike\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 613, in _load_from_module_spec
    setup = getattr(lib, 'setup')
AttributeError: module 'cogs.rs9' has no attribute 'setup'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Mike\Desktop\Discordbot\Seymour.py", line 21, in <module>
    client.load_extension(f'cogs.{filename[:-3]}')
  File "C:\Users\Mike\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 664, in load_extension
    self._load_from_module_spec(spec, name)
  File "C:\Users\Mike\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 616, in _load_from_module_spec
    raise errors.NoEntryPointError(key)
discord.ext.commands.errors.NoEntryPointError: Extension 'cogs.rs9' has no 'setup' function.
[Finished in 0.45s]

感谢您在此问题上提供的任何帮助。

标签: pythonpython-3.xdiscord.pyatom-editor

解决方案


cogs.rs9文件中,设置函数应该是不缩进的

import discord
import os
import random
from discord.ext import commands

class rs9(commands.Cog):
    def __init__(self, client):
        self.client = client

    # Put the commands here


def setup(client):
    client.add_cog(rs9(client))

推荐阅读