Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
68 lines (51 sloc) 2.5 KB
"""
This is the default module created by the `monium mkmodule <name>` command.
When the bot starts up, it will send "Hello, world!" to every channel it can
see.
The module loader will always load `module.py`, so this file will be your
entrypoint.
"""
import discord
from monium.module import Module
class HelloWorldModule(Module):
"""
Any class that extends monium.module.Module will be picked up as a module
"""
# These four variables should be filled out for `monium info`
# Especially the id, as it's required for logger name generation
id = "simple-hello-world"
name = "The Hello World Module(tm)"
version = (1, 0, 0)
authors = ["Admicos"]
def init(self):
"""
The init() method will be called after __init__(), so any initialization
should be done here.
Why not just use __init__()? Because the base Module class does some
setup in it's __init__(), and it's a little cleaner to just expose a
second method for user initialization.
It's not required to use this init, but it's recommended.
"""
# All modules automatically come with a logging.Logger instance with
# the module id as it's name. It's better to use this instead of just
# printing everything, as the logger will log instantly, whereas print
# will buffer, and potentially cause your logs to be misarranged.
self.logger.info("Hello, world!")
async def on_ready(self):
"""
This is a discord.py event. All discord.py events should be supported.
You can see a list over at:
http://discordpy.readthedocs.io/en/latest/api.html#event-reference
or at the module base classes source, as every supported event is listed
for IDE autocompletion.
This is also the point where you can reliably access self.client for
command registration, configuration or anything like that.
"""
# self.client is a instance of MoniumClient which is a class extending
# discord.Client, and is the main Discord interface you have, along
# with some monium-specific additions like the command handler
# (self.client.cmd) or configuration system (self.client.get_configuration_for(server_id))
# But those are for one of the next examples.
for channel in self.client.get_all_channels(): # type: discord.Channel
if channel.type == discord.ChannelType.text:
await self.client.send_message(channel, "Hello, world!")
You can’t perform that action at this time.