Skip to content

How to make a plugin.

Ccode-lang edited this page Oct 16, 2023 · 10 revisions

Introduction

When you run a Xander instance you may notice this line in your log:

[14/04/2023 11:47:35] Loading plugins

This is one of the most useful features of Xander at work. You can load Python scripts with a certain format as plugins to add extra commands (and features) to the bot without modifying the bot.py file directly.

Making your first plugin

A basic plugin looks like the below:

# You can import extra modules here if you need to

# Import the Xander plugin API bindings
from xander_plugin import *


# Called when the plugin is loaded.
def onload():
    # A simple call to the log() function from bot.py which prints to the log file.
    log("Example plugin loaded!")

# Called when a message is received. It must be async and has an input of a discord message object. (More information in discord.py docs)
async def onmessage(message):
    # An example of what we can do with a message object.  The message object is defined in the discord.py API.
    log(f"The message \"{message.content}\" was sent by {message.author.name}")

# A function called when the bot program exits.
def onexit():
    obj("Example plugin exit run.")
Clone this wiki locally