User Utilities

Utility functions for working with user and member instances

async user_utils.isAdmin(context: discord.ext.commands.context.Context) → bool

Returns true if context.author has the Admin role, else raises CommandPermissionError This is used with the @command.check decorator to facilitate authentication for elevated commands

async user_utils.isAtLeastInstructor(context: discord.ext.commands.context.Context) → bool

Returns true if context.author is either an admin or an instructor and False otherwise :param context: :return:

async user_utils.isInstructor(context: discord.ext.commands.context.Context) → bool

Returns true if context.author has the Instructor role, else raises CommandPermissionError This is used with the @command.check decorator to facilitate authentication for elevated commands

async user_utils.isStudent(context: discord.ext.commands.context.Context) → bool

Returns true if context.author has the Student role, false otherwise

async user_utils.membership_check(context: discord.ext.commands.context.Context, role_id: str, role_name: str, throw_exception: bool = True) → bool

Checks if the author of the message in question belongs to the parameterized role :param throw_exception: If true, will throw exception if user is not a member of the specified role :param context: Object containing metadata about the most recent message sent :param role_id: The UUID of the role for which we are checking for membership in :param role_name: The human-readable name of the role for which we are checking for membership in :return: True if user is belongs to role, False otherwise

async user_utils.userToMember(user: discord.user.User, bot: discord.ext.commands.bot.Bot) → Optional[discord.member.Member]

Resolves a user into a member of the guild. When the bot receives a direct message the author of the message is a User. To get information about this user as a member of a guild, a member instance is needed.

Parameters
  • user (User) – The user instance

  • bot (commands.Bot) – An instance of the bot

Returns

The member instance, or None if the user is not a member of the guild