discord.py 中的 Cog 和 Extension 有什么区别?

Whats the difference between a Cog and an Extension in discord.py?(discord.py 中的 Cog 和 Extension 有什么区别?)
本文介绍了discord.py 中的 Cog 和 Extension 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

在 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_messageon_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 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How do I make a list of all members in a discord server using discord.py?(如何使用 discord.py 列出不和谐服务器中的所有成员?)
how to change discord.py bot activity(如何更改 discord.py 机器人活动)
Issues with getting VoiceChannel.members and Guild.members to return a full list(让 VoiceChannel.members 和 Guild.members 返回完整列表的问题)
Add button components to a message (discord.py)(将按钮组件添加到消息(discord.py))
on_message() and @bot.command issue(on_message() 和@bot.command 问题)
How to edit a message in discord.py(如何在 discord.py 中编辑消息)