在 discord.py 文档中,有扩展:https://discordpy.readthedocs.io/en/stable/ext/commands/extensions.html和齿轮:https://discordpy.readthedocs.io/en/stable/ext/commands/cogs.html有什么区别?
In the discord.py documention, there are Extensions: https://discordpy.readthedocs.io/en/stable/ext/commands/extensions.html and Cogs: https://discordpy.readthedocs.io/en/stable/ext/commands/cogs.html what is the difference?
扩展是被加载的文件,当你调用 load_extension 时,将它们视为 discord.py 库导入的模块.导入发生后,一个 setup 函数被调用,并被传递给它被加载到的 Bot 实例......本质上是 module.setup(bot)代码>.就是这样,没有更多的扩展......通常这个设置函数调用 add_cog 将在下面描述,但是没有要求他们这样做.
Extensions are files that are loaded, think of them as modules that the discord.py library imports when you call load_extension. After the import happens, a setup function is called, and is passed the Bot instance that it was loaded into....essentially module.setup(bot). That is it, there is no more to extensions...typically this setup function calls add_cog which will be described next, however there is no requirement that they do so.
Cog 是从 commands.Cog 继承的类,并通过 add_cog 添加到机器人的 cog 列表中,这些类通常包含命令并充当"类别"对于这些命令.它还可以容纳诸如 on_message 或 on_member_join 等事件的侦听器.
A Cog is a class that inherits from commands.Cog and is added to the bot's list of cogs through add_cog, these classes typically house commands and act as a "category" for these commands. It can also house listeners for events such as on_message or on_member_join, etc.
TL;DR - 扩展是导入的模块,cogs 是类
这篇关于discord.py 中的 Cog 和 Extension 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
如何制作一个在 Python 中提供角色的不和谐机器人How to make a discord bot that gives roles in Python?(如何制作一个在 Python 中提供角色的不和谐机器人?)
Discord 机器人没有响应命令Discord bot isn#39;t responding to commands(Discord 机器人没有响应命令)
你能得到“关于我"吗?Discord 机器人的功能?Can you Get the quot;About mequot; feature on Discord bot#39;s? (Discord.py)(你能得到“关于我吗?Discord 机器人的功能?(不和谐.py))
message.channel.id Discord PYmessage.channel.id Discord PY(message.channel.id Discord PY)
如何在 heroku 上托管我的 discord.py 机器人?How do I host my discord.py bot on heroku?(如何在 heroku 上托管我的 discord.py 机器人?)
discord.py - 自动更改角色颜色discord.py - Automaticaly Change an Role Color(discord.py - 自动更改角色颜色)