WarnSystem¶
API Reference¶
-
class
warnsystem.api.
API
(bot, config)[source]¶ Interact with WarnSystem from your cog.
To import the cog and use the functions, type this in your code:
warnsystem = bot.get_cog('WarnSystem').api
Warning
If
warnsystem
isNone
, the cog is not loaded/installed. You won’t be able to interact with the API at this point.Tip
You can get the cog version by doing this
version = bot.get_cog('WarnSystem').__version__
Errors¶
Custom error handling used for the cog and the API.
If you need to prevent and exception, do it like this:
warnsystem = bot.get_cog('WarnSystem')
api = cog.api
errors = cog.errors
try:
await api.warn(5, user, "my random reason")
except discord.errors.Forbidden:
print("Missing permissions")
except errors.InvalidLevel:
print("Wrong warning level")
except:
# occurs for any exception
print("Fatal error")
else:
# executed if the try succeeded
print("All good")
finally:
# always executed
print("End of function")
-
exception
warnsystem.errors.
InvalidLevel
[source]¶ The level argument for
warn()
is wrong. It must be between 1 and 5.
-
exception
warnsystem.errors.
NotFound
[source]¶ Something was not found in the WarnSystem data. The meaning of this exception depends of what you called, it may be a missing WarnSystem channel.
-
exception
warnsystem.errors.
MissingMuteRole
[source]¶ You requested a mute warn but the mute role doesn’t exist. Call
maybe_create_role()
to fix this.
-
exception
warnsystem.errors.
BadArgument
[source]¶ The arguments provided for your request are wrong, check the types.
-
exception
warnsystem.errors.
MissingPermissions
[source]¶ The bot lacks a permission to do an action.
This is raised instead of
discord.errors.Forbidden
to prevent a useless API call, we check the bot’s permissions before calling.
-
exception
warnsystem.errors.
MemberTooHigh
[source]¶ The member to take action on is above the bot in the guild’s role hierarchy.
To fix this, set the bot’s top role above the member’s top role. For more informations about Discord Permissions, read this: https://support.discordapp.com/hc/en-us/articles/206029707
This is raised instead of
discord.errors.Forbidden
to prevent a useless API call, we check the bot’s permissions before calling.
-
exception
warnsystem.errors.
NotAllowedByHierarchy
[source]¶ The bot is set to respect the role hierarchy; the moderator requested a warn against someone equal or higher than him in the hierarchy, which is not allowed by Discord permissions rules.
The moderator must have a role higher than the warned member to continue.
Note
This cannot be raised if the admins disabled the role hierarchy check.