discord.ext.commands.errors.ExtensionNotFound:无法加载扩展名'cogs.manage'

时间:2019-12-18 17:31:40

标签: python discord.py

我正在将命令移动到齿轮并对其进行排序,但是我无法继续加载齿轮。

app.py

<div class="colorscripter-code" style="color:#010101;font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; position:relative !important;overflow:auto"><table class="colorscripter-code-table" style="margin:0;padding:0;border:none;background-color:#fafafa;border-radius:4px;" cellspacing="0" cellpadding="0"><tr><td style="padding:6px;border-right:2px solid #e5e5e5"><div style="margin:0;padding:0;word-break:normal;text-align:right;color:#666;font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace !important;line-height:130%"><div style="line-height:130%">1</div><div style="line-height:130%">2</div><div style="line-height:130%">3</div><div style="line-height:130%">4</div><div style="line-height:130%">5</div><div style="line-height:130%">6</div><div style="line-height:130%">7</div><div style="line-height:130%">8</div><div style="line-height:130%">9</div><div style="line-height:130%">10</div><div style="line-height:130%">11</div><div style="line-height:130%">12</div><div style="line-height:130%">13</div><div style="line-height:130%">14</div><div style="line-height:130%">15</div><div style="line-height:130%">16</div><div style="line-height:130%">17</div><div style="line-height:130%">18</div><div style="line-height:130%">19</div><div style="line-height:130%">20</div><div style="line-height:130%">21</div><div style="line-height:130%">22</div><div style="line-height:130%">23</div><div style="line-height:130%">24</div><div style="line-height:130%">25</div><div style="line-height:130%">26</div><div style="line-height:130%">27</div><div style="line-height:130%">28</div><div style="line-height:130%">29</div><div style="line-height:130%">30</div><div style="line-height:130%">31</div><div style="line-height:130%">32</div><div style="line-height:130%">33</div><div style="line-height:130%">34</div><div style="line-height:130%">35</div><div style="line-height:130%">36</div><div style="line-height:130%">37</div></div></td><td style="padding:6px 0;text-align:left"><div style="margin:0;padding:0;color:#010101;font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace !important;line-height:130%"><div style="padding:0 6px; white-space:pre; line-height:130%"><span style="color:#a71d5d">import</span>&nbsp;discord</div><div style="padding:0 6px; white-space:pre; line-height:130%"><span style="color:#a71d5d">import</span>&nbsp;asyncio</div><div style="padding:0 6px; white-space:pre; line-height:130%"><span style="color:#a71d5d">import</span>&nbsp;re</div><div style="padding:0 6px; white-space:pre; line-height:130%"><span style="color:#a71d5d">import</span>&nbsp;json</div><div style="padding:0 6px; white-space:pre; line-height:130%"><span style="color:#a71d5d">from</span>&nbsp;discord.ext&nbsp;<span style="color:#a71d5d">import</span>&nbsp;commands</div><div style="padding:0 6px; white-space:pre; line-height:130%">&nbsp;</div><div style="padding:0 6px; white-space:pre; line-height:130%"><span style="color:#999999">#Json&nbsp;Part</span></div><div style="padding:0 6px; white-space:pre; line-height:130%">with&nbsp;<span style="color:#066de2">open</span>(<span style="color:#63a35c">'config/setting.json'</span>)&nbsp;as&nbsp;json_file:</div><div style="padding:0 6px; white-space:pre; line-height:130%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;json_data&nbsp;<span style="color:#0086b3"></span><span style="color:#a71d5d">=</span>&nbsp;json.load(json_file)</div><div style="padding:0 6px; white-space:pre; line-height:130%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;token&nbsp;<span style="color:#0086b3"></span><span style="color:#a71d5d">=</span>&nbsp;json_data[<span style="color:#63a35c">"bot_token"</span>]</div><div style="padding:0 6px; white-space:pre; line-height:130%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prefix&nbsp;<span style="color:#0086b3"></span><span style="color:#a71d5d">=</span>&nbsp;json_data[<span style="color:#63a35c">"prefix"</span>]</div><div style="padding:0 6px; white-space:pre; line-height:130%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ver&nbsp;<span style="color:#0086b3"></span><span style="color:#a71d5d">=</span>&nbsp;json_data[<span style="color:#63a35c">"ver"</span>]</div><div style="padding:0 6px; white-space:pre; line-height:130%">&nbsp;</div><div style="padding:0 6px; white-space:pre; line-height:130%"><span style="color:#999999">#Bot&nbsp;Part</span></div><div style="padding:0 6px; white-space:pre; line-height:130%">bot&nbsp;<span style="color:#0086b3"></span><span style="color:#a71d5d">=</span>&nbsp;commands.Bot(command_prefix<span style="color:#0086b3"></span><span style="color:#a71d5d">=</span><span style="color:#63a35c">'%a'</span>&nbsp;%&nbsp;prefix)</div><div style="padding:0 6px; white-space:pre; line-height:130%">client&nbsp;<span style="color:#0086b3"></span><span style="color:#a71d5d">=</span>&nbsp;discord.Client()</div><div style="padding:0 6px; white-space:pre; line-height:130%">&nbsp;</div><div style="padding:0 6px; white-space:pre; line-height:130%">@client.event&nbsp;</div><div style="padding:0 6px; white-space:pre; line-height:130%">async&nbsp;<span style="color:#a71d5d">def</span>&nbsp;on_ready():</div><div style="padding:0 6px; white-space:pre; line-height:130%">&nbsp;</div><div style="padding:0 6px; white-space:pre; line-height:130%">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#066de2">print</span>(<span style="color:#63a35c">"Thanks&nbsp;for&nbsp;run&nbsp;this&nbsp;program.&nbsp;The&nbsp;version&nbsp;of&nbsp;this&nbsp;program&nbsp;is&nbsp;%s."</span>&nbsp;%&nbsp;ver)</div><div style="padding:0 6px; white-space:pre; line-height:130%">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#066de2">print</span>(client.user.name)</div><div style="padding:0 6px; white-space:pre; line-height:130%">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#066de2">print</span>(client.user.id)</div><div style="padding:0 6px; white-space:pre; line-height:130%">&nbsp;</div><div style="padding:0 6px; white-space:pre; line-height:130%">&nbsp;&nbsp;&nbsp;&nbsp;game&nbsp;<span style="color:#0086b3"></span><span style="color:#a71d5d">=</span>&nbsp;discord.Game(<span style="color:#63a35c">"!n.help&nbsp;|&nbsp;Alpha&nbsp;version"</span>)</div><div style="padding:0 6px; white-space:pre; line-height:130%">&nbsp;&nbsp;&nbsp;&nbsp;await&nbsp;client.change_presence(status<span style="color:#0086b3"></span><span style="color:#a71d5d">=</span>discord.Status.online,&nbsp;activity<span style="color:#0086b3"></span><span style="color:#a71d5d">=</span>game)</div><div style="padding:0 6px; white-space:pre; line-height:130%">&nbsp;</div><div style="padding:0 6px; white-space:pre; line-height:130%"><span style="color:#999999">#Cogs&nbsp;Part</span></div><div style="padding:0 6px; white-space:pre; line-height:130%">initial_extensions&nbsp;<span style="color:#0086b3"></span><span style="color:#a71d5d">=</span>&nbsp;[<span style="color:#63a35c">'cogs.manage'</span>,</div><div style="padding:0 6px; white-space:pre; line-height:130%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#63a35c">'cogs.command'</span>]</div><div style="padding:0 6px; white-space:pre; line-height:130%"><span style="color:#999999">#FIXME:&nbsp;discord.ext.commands.errors.ExtensionNotFound:&nbsp;Extension&nbsp;'cogs.manage'&nbsp;could&nbsp;not&nbsp;be&nbsp;loaded.</span></div><div style="padding:0 6px; white-space:pre; line-height:130%"><span style="color:#a71d5d">if</span>&nbsp;__name__&nbsp;<span style="color:#0086b3"></span><span style="color:#a71d5d">=</span><span style="color:#0086b3"></span><span style="color:#a71d5d">=</span>&nbsp;<span style="color:#63a35c">'__main__'</span>:</div><div style="padding:0 6px; white-space:pre; line-height:130%">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a71d5d">for</span>&nbsp;extenstion&nbsp;<span style="color:#a71d5d">in</span>&nbsp;initial_extensions:</div><div style="padding:0 6px; white-space:pre; line-height:130%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bot.load_extension(extenstion)</div><div style="padding:0 6px; white-space:pre; line-height:130%">&nbsp;</div><div style="padding:0 6px; white-space:pre; line-height:130%">client.run(token)&nbsp;&nbsp;&nbsp;&nbsp;</div><div style="padding:0 6px; white-space:pre; line-height:130%">&nbsp;</div></div><div style="text-align:right;margin-top:-13px;margin-right:5px;font-size:9px;font-style:italic"><a href="http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter</a></div></td><td style="vertical-align:bottom;padding:0 2px 4px 0"><a href="http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white"><span style="font-size:9px;word-break:normal;background-color:#e5e5e5;color:white;border-radius:10px;padding:1px">cs</span></a></td></tr></table></div>

manage.py

<div class="colorscripter-code" style="color:#010101;font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace !important; position:relative !important;overflow:auto"><table class="colorscripter-code-table" style="margin:0;padding:0;border:none;background-color:#fafafa;border-radius:4px;" cellspacing="0" cellpadding="0"><tr><td style="padding:6px;border-right:2px solid #e5e5e5"><div style="margin:0;padding:0;word-break:normal;text-align:right;color:#666;font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace !important;line-height:130%"><div style="line-height:130%">1</div><div style="line-height:130%">2</div><div style="line-height:130%">3</div><div style="line-height:130%">4</div><div style="line-height:130%">5</div><div style="line-height:130%">6</div><div style="line-height:130%">7</div><div style="line-height:130%">8</div><div style="line-height:130%">9</div><div style="line-height:130%">10</div><div style="line-height:130%">11</div><div style="line-height:130%">12</div><div style="line-height:130%">13</div><div style="line-height:130%">14</div><div style="line-height:130%">15</div><div style="line-height:130%">16</div><div style="line-height:130%">17</div><div style="line-height:130%">18</div><div style="line-height:130%">19</div><div style="line-height:130%">20</div><div style="line-height:130%">21</div><div style="line-height:130%">22</div><div style="line-height:130%">23</div><div style="line-height:130%">24</div></div></td><td style="padding:6px 0;text-align:left"><div style="margin:0;padding:0;color:#010101;font-family:Consolas, 'Liberation Mono', Menlo, Courier, monospace !important;line-height:130%"><div style="padding:0 6px; white-space:pre; line-height:130%"><span style="color:#a71d5d">import</span>&nbsp;discord</div><div style="padding:0 6px; white-space:pre; line-height:130%"><span style="color:#a71d5d">import</span>&nbsp;asyncio</div><div style="padding:0 6px; white-space:pre; line-height:130%"><span style="color:#a71d5d">import</span>&nbsp;re</div><div style="padding:0 6px; white-space:pre; line-height:130%"><span style="color:#a71d5d">import</span>&nbsp;json</div><div style="padding:0 6px; white-space:pre; line-height:130%"><span style="color:#a71d5d">from</span>&nbsp;discord.ext&nbsp;<span style="color:#a71d5d">import</span>&nbsp;commands</div><div style="padding:0 6px; white-space:pre; line-height:130%">&nbsp;</div><div style="padding:0 6px; white-space:pre; line-height:130%"><span style="color:#a71d5d">class</span>&nbsp;manage(Commands.Cog):</div><div style="padding:0 6px; white-space:pre; line-height:130%">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a71d5d">def</span>&nbsp;__init__(self,&nbsp;bot):</div><div style="padding:0 6px; white-space:pre; line-height:130%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.bot&nbsp;<span style="color:#0086b3"></span><span style="color:#a71d5d">=</span>&nbsp;bot</div><div style="padding:0 6px; white-space:pre; line-height:130%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div style="padding:0 6px; white-space:pre; line-height:130%">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a71d5d">def</span>&nbsp;command(self):</div><div style="padding:0 6px; white-space:pre; line-height:130%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#999999">#Json&nbsp;part</span></div><div style="padding:0 6px; white-space:pre; line-height:130%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with&nbsp;<span style="color:#066de2">open</span>(<span style="color:#63a35c">'config/setting.json'</span>)&nbsp;as&nbsp;json_file:</div><div style="padding:0 6px; white-space:pre; line-height:130%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;json_data&nbsp;<span style="color:#0086b3"></span><span style="color:#a71d5d">=</span>&nbsp;json.load(json_file)</div><div style="padding:0 6px; white-space:pre; line-height:130%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prefix&nbsp;<span style="color:#0086b3"></span><span style="color:#a71d5d">=</span>&nbsp;json_data[<span style="color:#63a35c">"prefix"</span>]</div><div style="padding:0 6px; white-space:pre; line-height:130%">&nbsp;</div><div style="padding:0 6px; white-space:pre; line-height:130%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#999999">#commands&nbsp;part</span></div><div style="padding:0 6px; white-space:pre; line-height:130%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@commands.command()</div><div style="padding:0 6px; white-space:pre; line-height:130%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;async&nbsp;<span style="color:#a71d5d">def</span>&nbsp;on_message(message):</div><div style="padding:0 6px; white-space:pre; line-height:130%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a71d5d">if</span>&nbsp;message.author&nbsp;<span style="color:#0086b3"></span><span style="color:#a71d5d">=</span><span style="color:#0086b3"></span><span style="color:#a71d5d">=</span>&nbsp;client.user:</div><div style="padding:0 6px; white-space:pre; line-height:130%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a71d5d">return</span></div><div style="padding:0 6px; white-space:pre; line-height:130%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div style="padding:0 6px; white-space:pre; line-height:130%">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#a71d5d">def</span>&nbsp;setup(bot):</div><div style="padding:0 6px; white-space:pre; line-height:130%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bot.add_cog(manageCog(bot))</div></div></td><td style="vertical-align:bottom;padding:0 2px 4px 0"><a href="http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white"><span style="font-size:9px;word-break:normal;background-color:#e5e5e5;color:white;border-radius:10px;padding:1px">cs</span></a></td></tr></table></div>

1 个答案:

答案 0 :(得分:0)

manage.py是文件夹cogs中的子模块吗?因为那是您引用它的方式。参见the documentation for Bot.load_extension

此外,您的setup函数需要是全局的,即不是manage类中的方法,并且应该使用现有的类,因此您的manage机器人可能也可以。我不确定manageCog是什么,但是您没有在任何地方显示它。

有关齿轮的更多信息,请参见https://discordpy.readthedocs.io/en/latest/ext/commands/cogs.html

此外,on_message是一个事件,而不是命令,因此需要用@commands.Cog.listener()(而不是@commands.command())修饰。无论哪种方式,它都不应该在另一个方法中,而应该在类/齿轮中使用它自己的方法。

供以后参考,您无需将HTML格式的代码粘贴到JavaScript代码段中,只需将代码直接添加到带有代码块的问题中即可。
有关降价的帮助,请参见https://stackoverflow.com/editing-help