問題描述
在 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模板網!