API Reference¶
Importing¶
The recommended way to import easydiscord is as followed:
import easydiscord
from easydiscord import *
This will import all the necessary items into your global scope. Version Info ————
Initiative Functions¶
-
easydiscord.get_bot(token: str, *args, **kwargs)¶ Generates a new
Botinstance. You should avoid callingBot()directly, instead, use thisget_bot()constructor.Parameters: token – ( str): Your bot’s API token.Keyword Arguments: verbose – ( bool): Whether or not certain messages should be printed usingprint(). Defaults toTrue.Returns: An instance of Bot.Examples:
bot = easydiscord.get_bot("MY_API_TOKEN")
The Bot Class¶
-
class
easydiscord.Bot(token, *, verbose: bool = True, severity='high')¶ The
Botobject that represents a discord bot.Call
config()method after that bot is initiated.Parameters: Raises: AttributeError– When severity is incorrectly set.-
add_command(func, *, name=None)¶ Adds a handler to a command. The
namekeyword argument can be used to override the function name.Parameters: - func – (
function): The command handler itself, it can be a coroutine or not. - name – (
str): The optional replacement name for your command. IfNoneis passed, the function name will be used.
Returns: The function provided by argument
func.Examples:
def hi(ctx): print('hi') bot.add_command(hi)
- func – (
-
add_event(func, *, name=None)¶ Adds an event handler. The
namekeyword argument can be used to override the function’s name.Parameters: - func – (
function): The event handler itself, it can be a coroutine or not. - name – (
str): The optional replacement name for your event handler. IfNoneis passed, the function name will be used.
Returns: The function provided by argument
func.Examples:
def on_message(message): print('hi') bot.add_event(on_message)
- func – (
-
add_group(group: easydiscord.core.Group, *, name=None)¶ Adds a group of commands. The
namekeyword argument can be used to override the class name.Parameters: Returns: The class provided by argument
group.Raises: EasyDiscordError– When thegroupargument isn’t a subclass ofGroup.Examples:
class Greetings(easydiscord.Group): @property def register(self): return [self.hi] def hi(self, ctx): print('hi') bot.add_group(Greetings)
-
config(prefix='$', default_on_ready=True, desc='', help_format=None)¶ Configures this
Bot.Parameters: Returns: The
Botitself.Return type:
-
on_ready()¶ This method is a coroutine.
The default
on_readyevent. Nothing will be printed if initialverboseis set toFalse.The following will be printed:
Logged in as: Bot : <bot-name> ID : <bot-id> ------
Returns: None
-
process_message(message)¶ This method is a coroutine.
This function has not been implemented yet.
-
reload()¶ Resets the bot. Shuts the bot down and restarts it.
Returns: None
-
reply(current, reply_message)¶
-
setup(prefix='$', default_on_ready=True, desc='', help_format=None)¶ An alias of
config().Configures this
Bot.Parameters: Returns: The
Botitself.Return type:
-
start_bot()¶ Starts the main loop of the discord bot. Do not add anything after this command.
Returns: None
-
bot¶ Retrieve the background discord.py
Botinstance. Do not use this unless you have a clear idea on integrating this into your code.Returns: A discord.py Bot.Return type: BotRaises: EasyDiscordError– WhenBot.config()is not called first.
-
prefix¶ The prefix from your
Bot’s chat commands.Returns: The string representation of your Bot’s prefix.Return type: strRaises: EasyDiscordError– WhenBot.config()is not called first.
-
Other Objects¶
-
class
easydiscord.Command(name, callback, **kwargs)¶ A subclass of python.py’s
Command. This should be used as theCommandobject.
-
class
easydiscord.Group¶ This is the superclass for all grouping of commands. See
add_group()for exmaples.Raises: TypeError– Whenregister()is not overwritten by subclasses.-
set_name(meth, name)¶ Sets/changes the name from the method. This function is not required, the command name will remain to be the method’s name if
set_name()is not called. After the method’s name has been changed, the command will use the new name. Only useset_name()inregister().Parameters: - meth – (
method): The method whom name will be changed. - name – (
str): The name to change it to.
Returns: The method provided by argument
meth.Examples:
class Greetings(easydiscord.Group): @property def register(self): self.set_name(self.hi, 'hello') # The registered command is not called 'hello' return [self.hi] def hi(self, ctx): print('hi') bot.add_group(Greetings)
- meth – (
-
Exceptions¶
-
exception
easydiscord.exceptions.EasyDiscordError¶ This is an overall exception that all easydiscord functions raises when encountered a problem. More
Exceptionwill be added in the future.-
classmethod
no_coro()¶
-
classmethod
-
exception
easydiscord.exceptions.EasyDiscordWarning¶ This is an overall warning that all easydiscord functions raises when encountered a minor problem. More
UserWarningwill be added in the future.-
classmethod
no_coro()¶
-
classmethod