Редактор Atom и Discord с Python, получая ошибку discord.ext.commands.errors.NoEntryPointError: Расширение

#python #python-3.x #discord.py #atom-editor

#python #python-3.x #discord.py #atom-editor

Вопрос:

в основных строках кода 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]}')
 

на rs9.py в Cog: строки 1-9 ниже.

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

class rs9(commands.Cog):

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

У меня такой же точный формат, введенный для команды eightball в другом cog, который работает нормально. по какой-то причине этот винтик продолжает выбрасывать коды:

Настройка блока:

         def setup(client):
            client.add_cog(rs9(client))
 
 Traceback (most recent call last):
  File "C:UsersMikeAppDataLocalProgramsPythonPython39libsite-packagesdiscordextcommandsbot.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:UsersMikeDesktopDiscordbotSeymour.py", line 21, in <module>
    client.load_extension(f'cogs.{filename[:-3]}')
  File "C:UsersMikeAppDataLocalProgramsPythonPython39libsite-packagesdiscordextcommandsbot.py", line 664, in load_extension
    self._load_from_module_spec(spec, name)
  File "C:UsersMikeAppDataLocalProgramsPythonPython39libsite-packagesdiscordextcommandsbot.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]
 

Спасибо за любую помощь по этому вопросу.

Комментарии:

1. Хотя сам ответ хорош, я бы рекомендовал изменить заголовок, чтобы он больше отражал то, что вы спрашиваете, и какова основная тема, но в некотором смысле. Например. Редактор Atom и Discord, получая discord.ext.commands.errors. NoEntryPointError: расширение

2. Посмотрите здесь => Как мне написать хорошее название?

Ответ №1:

В 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))