- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
随着我的机器人越来越大,我正在尝试实现齿轮,但是我遇到了一个问题。我已设置并准备好整个代码,但由于某些奇怪的原因,我不断收到此错误:
Traceback (most recent call last):
File "C:\Users\Lauras\Desktop\Akagi Bot\main.py", line 107, in <module>
bot.add_cog("cogs.fun")
File "C:\Users\Lauras\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\ext\commands\bot.py", line 477, in add_cog
raise TypeError('cogs must derive from Cog')
TypeError: cogs must derive from Cog
我在 main.py 上的代码如下所示:
import discord
import asyncio
import typing
import random
import json
import oauth
from discord.ext import commands
bot = commands.Bot(command_prefix='~')
@bot.event
async def on_ready():
await bot.change_presence(activity=discord.Activity(name='with Kaga :3',type=0))
print (discord.__version__)
print(f"{bot.user.name} - {bot.user.id}")
print ('Akagi is ready to serve the Commander :3 !')
bot.add_cog("cogs.fun")
bot.run(oauth.bot_token)
“有趣”的齿轮如下:
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix='~')
class FunCog:
def __init__(self, bot):
self.bot = bot
@commands.command()
async def hug(self, ctx):
await ctx.send('has been hugged by', file=discord.File('iloveyou.gif'))
pass
def setup(bot: commands.Bot):
bot.add_cog(FunCog(bot))
可能是什么问题?我也在使用 discord.py 重写。谢谢!
最佳答案
我建议查看 https://discordpy.readthedocs.io/en/latest/ext/commands/cogs.html这将帮助您更好地了解 Cogs。
首先,您需要将 bot.add_cog("cogs.fun")
更改为 bot.load_extension("cogs.fun")
这不是必需的,但您不需要再次定义 bot
。将 def setup(bot: commands.Bot):
更改为 def setup(bot):
您还需要将 class FunCog:
更改为 class FunCog(commands.Cog):
我建议在重写版本的新更新发布时及时了解更改。这是一个快速查看 working cog file. 的示例.希望这有帮助!最大。
关于python - discord.py 重写 : TypeError: cogs must derive from Cog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55231877/
随着我的机器人越来越大,我正在尝试实现齿轮,但是我遇到了一个问题。我已设置并准备好整个代码,但由于某些奇怪的原因,我不断收到此错误: Traceback (most recent call l
是否可以为每个齿轮设置前缀? 例如,带有管理命令的 Cog 具有前缀 pa!,而一些有趣命令的 cog 具有前缀 pf!。 不使用 on_message。 编辑:我想我必须更详细地介绍: 我的 ser
有谁知道 Pharo 和 Squeak 的 Cog VM 是否能够使用如下访问器优化简单的间接变量访问: SomeClass>>someProperty ^ someProperty Some
我写了一个使用 cogs 的 discord 机器人。这是我在每个扩展/齿轮中加载的代码: import discord import os from discord.ext import comma
我已经设置了一个 discord.py cog,可以使用了。有一个问题,如何为命令设置别名?我会在下面给你我的代码,看看我还需要做什么: # Imports from discord.ext impo
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭去年。 Improve th
我的代码: import discord from discord.ext import commands import re import os class Help2(commands.Cog):
我们正在使用和添加/删除某些 js 事件的 fa-spin。在 3x 下很容易看到的问题是齿轮不围绕固定轴旋转。我怀疑这是因为图标本身 (SVG) 被 Chrome 报告为 42 x 49 像素,即使
我到处搜索这个问题,但找不到答案。 我刚刚开始学习 discord.py,之前的 python 知识很少,如果这个问题看起来很简单,我很抱歉,我只使用 YouTube 教程就做了大约 12 个小时。
我有一个相当大的 Discord 机器人。它有超过 1000 行代码。当我在 Youtube 和这里研究如何做到这一点时,似乎没有任何效果。我想知道是否有人可以解释如何正确使用齿轮,可能是照片示例
我想让它尽可能原生。所以我需要一种获取系统图标的可能性。 我唯一能找到的是如何获取对话框图标,例如SWT.ICON_ERROR等。是否有机会获得其他系统图标,如打开、保存、复制等? 最佳答案 目前 S
@commands.Cog.listener() async def on_message(self, message): channel = self.client.get_channel(
根据他们的指南,这太奇怪了 here ,我添加了一个带有 glyphicon glyphicon-cog 的跨度......但是,当加载我的页面时,它实际上显示了信封 - 这是 glyphicon g
如标题所述:我想创建一个 3D 齿轮,它有 10 个齿,围绕其中心旋转(就像齿轮一样)。齿轮有方形齿,为了简单起见,齿间有平坦的侧面 - 这个齿轮上没有曲线。 齿轮一侧的可视化效果。请注意,角度并非
我对 Unix/Linux 系统很陌生,我在我的 Windows 机器上编写了这个程序,所以它工作得很好,我查看了 this并且很困惑。 这是我的全局代码: COGS = [path.split("\
最近我的 bot 越来越大,我花时间重写代码以使其与 Discord Py 的 cogs 系统一起工作 我已经正确调整了所有代码,但是我停止工作的所有 on_message 事件都没有抛出任何类型的错
我正在尝试使用 VMware 和主机 macOS 在 Ubuntu 上运行 WPE WebKit,但我收到以下错误消息: ➜ flatpak run org.wpe.Cog -P fdo http:
当我尝试加载位于模块文件夹中的配置扩展时,我这样做,但它不起作用: bot.load_extension("modules/config") 当我将其移动到主 python 文件所在的同一文件夹中时,
我在 bot.py 文件中定义了一个名为“前缀”的变量,该变量可以在稍后的命令中使用,例如显示给用户。它的目的是简单地存储机器人前缀。但是,我不知道如何在其他 cog 文件中使用此变量。 bot.py
我正在尝试在 Cog 中集成一个基本的 aiohttp 网络服务器(使用 discord-py 重写)。我正在为齿轮使用以下代码: from aiohttp import web import dis
我是一名优秀的程序员,十分优秀!