Skip to content
Ted edited this page Apr 25, 2023 · 13 revisions

To keep a common shape for all cogs, it is best to organize the imports properly. We suggest you to take inspiration from this.

Imports

  • π—˜π—«π—§π—˜π—₯π—‘π—”π—Ÿ π—œπ— π—£π—’π—₯𝗧
  • 𝗕𝗒𝗧.π—”π—¦π—¦π—œπ—¦π—§π—”π—‘π—§ π—œπ— π—£π—’π—₯𝗧𝗦
    • Handlers
    • Services
    • Settings
  • π—•π—’π—§π—”π—¦π—¦π—œπ—¦π—§π—”π—‘π—§ 𝗕𝗒𝗧
  • 𝗔𝗗𝗗𝗒𝗑
    • Init
    • Commands
    • Events
    • Handlers
    • Services
    • Settings
# 𝗔𝗨𝗧𝗛𝗒π—₯:

# π—˜π—«π—§π—˜π—₯π—‘π—”π—Ÿ π—œπ— π—£π—’π—₯𝗧
# -

# 𝗕𝗒𝗧.π—”π—¦π—¦π—œπ—¦π—§π—”π—‘π—§ π—œπ— π—£π—’π—₯𝗧𝗦
# -

# π—•π—’π—§π—”π—¦π—¦π—œπ—¦π—§π—”π—‘π—§ 𝗕𝗒𝗧 
# -

# 𝗔𝗗𝗗𝗒𝗑
# -

Class

  • π—˜π—©π—˜π—‘π—§π—¦
  • π—”π—¨π—§π—’π—–π—’π— π—£π—Ÿπ—˜π—§π—˜
  • 𝗖𝗒𝗠𝗠𝗔𝗑𝗗𝗦
class Example(commands.Cog):
    
    def __init__(self, bot):
        self.bot = bot


    # π—˜π—©π—˜π—‘π—§π—¦
    # Event on Ready
    @commands.Cog.listener()
    async def on_ready(self):
        await eventOnReady.onReady()


    # π—”π—¨π—§π—’π—–π—’π— π—£π—Ÿπ—˜π—§π—˜
    # Autocomplete for example
    async def getExample(ctx: discord.AutocompleteContext):
    return []


    # 𝗖𝗒𝗠𝗠𝗔𝗑𝗗𝗦
    # Commands groups
    groupExample = discordCommands.SlashCommandGroup(init.cogName, "Example description")
    groupSub = groupLevelSystem.create_subgroup("subExample", "Exemple sub description")

    # Verify if the bot has the prerequisites permissions
    @groupExample .command(name="requirements", description="Check the prerequisites permissions of the addon.")
    async def cmdPermissions(self, ctx: commands.Context):
        await DiscordLogger.info(ctx, init.cogName, ctx.author.name + " has used the requirements command.", str(ctx.command))
        await commandRequirements.checkRequirements(ctx)



def setup(bot):
    if debug: Logger.debug("Example")
    handlerDatabaseInit.databaseInit()
    bot.add_cog(Example(bot))

Clone this wiki locally