Skip to content

Creating a plugin

Baz edited this page Feb 28, 2025 · 1 revision

Plugins

A plugin is essentially a discord.py Cog which you can let the bot use

Installing a plugin

To install a plugin, place the plugin python file inside the plugins folder. A settings file will be created when the bot is ran with this plugin installed. You should also see the text Loaded plugin: {plugin name} when you run the bot.

Required code

Make sure that the following code is placed inside the __init__ function of your Cog:

self.name = type(self).__name__
self.cfname = f"{self.name.lower()}.json"
if not os.path.exists(f"./plugins/config/{self.cfname}"):
    x = open(f"./plugins/config/{self.cfname}", "w")
    x.write('{"__version__" : "1.0.0", "author" : "your_github_username"}') # This can be changed to add your own custom settings. Also add your username here.
    x.close()
with open(f"./plugins/config/{self.cfname}", "r") as c:
    self.config = json.load(c)

and the following code is used before creating a Cog class:

import json
import os

with open("settings.json", "r") as f:
    settings = json.load(f)

These allow the code to access the global configuration and the plugin's own configuration. For an example of starting a plugin, please look at template.py.

Publishing your plugin

To publish a plugin to this repo, you must reach out to me and send the code in a .txt format, where it will be reviewed before being added.

Clone this wiki locally