dimscord/helpers

Utilities for every discord object. It mostly contains helper procedures. You can use this for getting an avatar url and permission checking without the hassle for doing complicated bitwise work.

Procs

proc defaultAvatarUrl(u: User): string {...}{.raises: [ValueError], tags: [].}
Returns the default avatar for a user.   Source Edit
proc avatarUrl(u: User; fmt = "png"; size = 128): string {...}{.
    raises: [ValueError, UnpackError], tags: [].}
Gets a user's avatar url. If user does not have an avatar it will return default avatar of the user.   Source Edit
proc iconUrl(e: Emoji; fmt = "png"; size = 128): string {...}{.raises: [ValueError], tags: [].}
Gets an emoji's url.   Source Edit
proc iconUrl(g: Guild; fmt = "png"; size = 128): string {...}{.
    raises: [ValueError, UnpackError], tags: [].}
Get icon url for guild.   Source Edit
proc `$`(u: User): string {...}{.raises: [ValueError], tags: [].}
Stringifies a user. This would return something like MrDude#6969   Source Edit
proc `@`(u: User; nick = false): string {...}{.raises: [ValueError], tags: [].}
Mentions a user.   Source Edit
proc `@`(r: Role): string {...}{.raises: [ValueError], tags: [].}
Mentions a role.   Source Edit
proc `@`(g: GuildChannel): string {...}{.raises: [ValueError], tags: [].}
Mentions a guild channel.   Source Edit
proc `$`(g: GuildChannel): string {...}{.raises: [ValueError], tags: [].}
Stringifies a guild channel. This would return something like #general   Source Edit
proc getGuildWidget(guild_id, style: string): string {...}{.raises: [ValueError], tags: [].}
Gets a guild widget. https://discord.com/developers/docs/resources/guild#get-guild-widget-image-widget-style-options   Source Edit
proc timestamp(id: string): Time {...}{.raises: [ValueError], tags: [].}
Gets a timestamp from a Discord ID.   Source Edit
proc perms(p: PermObj): int {...}{.raises: [], tags: [].}
Gets the total permissions.   Source Edit
proc permCheck(perms, perm: int): bool {...}{.raises: [], tags: [].}
Checks if the set of permissions has the specific permission.   Source Edit
proc permCheck(perms: int; p: PermObj): bool {...}{.raises: [UnpackError], tags: [].}
Just like permCheck, but with a PermObj.   Source Edit
proc computePerms(guild: Guild; role: Role): PermObj {...}{.raises: [KeyError], tags: [].}
Computes the guild permissions for a role.   Source Edit
proc computePerms(guild: Guild; member: Member): PermObj {...}{.raises: [KeyError], tags: [].}
Computes the guild permissions for a member.   Source Edit
proc computePerms(guild: Guild; member: Member; channel: GuildChannel): PermObj {...}{.
    raises: [KeyError, ValueError], tags: [].}
Returns the permissions for the guild member of the channel. For permission checking you can do something like this:
cast[int](setofpermshere).permCheck(PermObj(
    allowed: {permExample}
))
  Source Edit
proc createBotInvite(client_id: string; permissions: set[PermissionFlags] = {};
                    guild_id = ""; disable_guild_select = false): string {...}{.raises: [],
    tags: [].}

Creates an invite link for the bot of the form.

Example: https://discord.com/api/oauth2/authorize?client_id=666&scope=bot&permissions=1

See https://discord.com/developers/docs/topics/oauth2#bots for more information.

  Source Edit
proc stripUserMentions(m: Message): string {...}{.raises: [ValueError, RegexError], tags: [].}
Strips out user mentions. Example: <@1234567890> to @TheMostMysteriousUser#0000   Source Edit
proc stripRoleMentions(m: Message): string {...}{.raises: [ValueError, RegexError], tags: [].}
Strips out role mentions. Example: <@&123456890> to @1243456890   Source Edit
proc stripChannelMentions(m: Message): string {...}{.raises: [ValueError, RegexError],
    tags: [].}
Strips out channel mentions. Example: <#123456790> to #such-a_long-time-ago or #123456790   Source Edit
proc stripMentions(m: Message): string {...}{.raises: [ValueError, RegexError], tags: [].}
Strips all mentions.   Source Edit