tripulse's own Discord bot which serves a lot of unique features that other bots fail to deliver.
As you may have probably guessed, this is written in Python 3 for doing the work with Discord it uses the sophisticated Discord.py API. You're assumed to have a little of experience with MongoDB.
- clone the repository
- type in TTY
pip3 install -r requirements.txt
- make a
config.yml
in the current folder, which defines how the bot acts, structure it somewhat like this:credentials: discord: token: '' # register your app then put the token. reddit: # required for the 'meme' command. client_id: '' # register an app on reddit then fill. client_secret: '' # ... mongodb_url: '' # setup a MongoDB database then retrieve the # connection URI from the cluster. defaults: prefix: '.' # set it to whatever you want. loglevel: 20 # means logging.INFO level.
- Optionally, to configure the log-level in the console, set
loglevel
to any of these values, by default it's set toINFO
level.
- Optionally, to configure the log-level in the console, set
To contribute to this project you should follow the idioms described below, if not then core developers might have to do extra effort cleaning up the code to match the idioms, sometimes not even accepting the PR.
cogs
folder has all the command modules in it, each module is separated based on its usage.__init__.py
loads all command modules and handles their exceptions.
requirements.txt
is where all the required external dependencies stored in thepip freeze
format.
Moving to cogs/
you'll see a lot of Python modules, each one has multiple categories referred to as so called "cogs
" in the Discord.py convention.
Categories are always that inherit from Cog
. The syntax is somewhat like this:
class MyCategory(Cog):
...
Free floating commands are not supported, they should be wrapped in a Cog
. A command is a coroutine (aka. async
function). Decorated with command
and must accept a positional argument.
class MyCategory(Cog):
@command
async def dosomething(ctx):
...
To export these classes to be picked up and be loaded, append a __cogexport__
at the end all the class definitions
. It could be any iterable object that yields classes inherited from Cog
, if not then the class is discarded.
__cogexport__ = [MyCategory, SomeCategory]
The bot has a logger attached to it, which can be used later on for intentions of tracing back. In a command it can be
acquired through ctx.bot.logger
.