python - 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]
感谢您在此问题上提供的任何帮助。
解决方案
在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))
推荐阅读
- linux - 问:如何在 tcl/tk 脚本中编写 file.CSV
- java - 按字段分组并计算java 8中的非空字段
- amazon-web-services - 如何将 Amazon 状态语言 json 渲染到图像?
- c++ - clang 格式重排评论不正确且不可重复
- azure - 测试 Azure Functions 时如何调用 ConfigureAppConfiguration
- amazon-web-services - AWS API Gateway、EventBridge:指定的选择表达式无效
- python - 替换 np.array 中的字符串字符
- kubernetes - 在节点故障的情况下,如何抑制在其他节点上再次启动 Job-based Pod?
- project-reactor - 为什么连接池获得的大小是-1?
- node.js - 我应该如何为以下标准创建 mongodb 数据库设计