-
Couldn't load subscription status.
- Fork 0
How to make a plugin.
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.
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.")Config is a module that holds all Xander configurations. It is written in Python for simplicity and compatibility with Python. (Exact definitions in config.py)
A function that prints line to the terminal with a timestamp and saves the message to log.txt. It returns nothing.
A function that can be used to create moderator logs in the modlog channel defined in config.py. string is the message that is sent to the modlog channel but the bot. message is the message variable of the moderated message. (message is required because it is used to differentiate servers) When delete is True the message referenced to by message is deleted after sending string the the modlog channel.
client is the client object of the bot. More information is in the discord.py documentation.
help_menu is the help menu dictionary. It can be interacted with by plugins to add help entries for them.
The voice client object of the bot if it is connected to a voice channel. Equals None if not connected to a channel. Check discord.py documentation to see how a voice client object works.
Get the variable associated with a keyword from the bot.py file.
Add a help menu entry for the plugin under the name feature_name and with the information provided in info.
Join a voice channel passed in channel. If connected already this method does nothing.
Leave the currently connected voice channel. If not connected this method does nothing.