pxlsspace / PxlsBot

Modular Discord bot
ISC License
4 stars 2 forks source link

Reorganize project to mimick discord.py's extension functionality #16

Closed netux closed 3 years ago

netux commented 3 years ago

This PR's main focus is merging "events" and "commands" into a single concept: extensions. Extensions are based on the discord.py's command extension in that they are files with an exported setup(client) function. They can be loaded and unloaded at will, and are based on files with an exported setup() function.

Another idea borrowed from discord.py's practices is making the Discord Client instance the "center of truth". As a primer, this PR extends Discord.js's Client to hold loaded extensions and registered commands, as well as adding manage both. This allows us to use the Client as a registry of things related to it, as opposed to how before, for example, command files were read from the commands/ folder on each use, using a function defined in utils.js.

Yet another concept taken is the idea of a Context object, which holds fields related to the command execution context (e.g message, command executed, argument specified, etc.). This Context object is passed on to the execute() function of each command when it is executed. This helps keep execute() arguments clean, while also allowing for extensibility without much hassle.

This PR also: