Utilities and helper functions for every discord object.
- You can use this for getting avatars, icons, get timestamp from id, permission checking without
the hassle for doing complicated bitwise work.
- Furthermore, you can also use this to waitFor a certain event and waitForRaw for raw json handling before dimscord handles them.
Procs
proc `$`(g: GuildChannel): string {....raises: [ValueError], tags: [], forbids: [].}
- Stringifies a guild channel. This would return something like #general Source Edit
proc `@`(a: ApplicationCommand): string {....raises: [ValueError], tags: [], forbids: [].}
- Mentions a slash command. Source Edit
proc `@`(g: GuildChannel): string {....raises: [ValueError], tags: [], forbids: [].}
- Mentions a guild channel. Source Edit
proc add(component: var MessageComponent; item: MessageComponent) {....raises: [], tags: [], forbids: [].}
- Add another component onto an ActionRow Source Edit
proc add(component: var MessageComponent; item: SelectMenuOption) {....raises: [], tags: [], forbids: [].}
- Add another menu option onto the select menu Source Edit
proc checkActionRow(row: MessageComponent) {....raises: [], tags: [], forbids: [].}
-
Checks if an action row meets these requirements
- A row cannot contain another row
- If a row contains buttons, then it can only have 5 buttons
- If a row contains buttons, then it cannot contains select menu
- If a row contiains a select menu, then there can only be one select menu
Throws an AssertionDefect if any of these checks fail
Source Edit proc computePerms(guild: Guild; member: Member): PermObj {....raises: [KeyError], tags: [], forbids: [].}
- Computes the guild permissions for a member. Source Edit
proc computePerms(guild: Guild; member: Member; channel: GuildChannel): PermObj {. ...raises: [KeyError], tags: [], forbids: [].}
-
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: [], forbids: [].}
-
Creates an invite link for the bot of the form.
Example: https://discord.com/api/oauth2/authorize?client_id=1234&scope=bot&permissions=1
See https://discord.com/developers/docs/topics/oauth2#bots for more information.
Source Edit proc defaultAvatarUrl(u: User): string {....raises: [ValueError], tags: [], forbids: [].}
- Returns the default avatar for a user. Source Edit
proc eventCover(e: GuildScheduledEvent; fmt = "png"): string {....raises: [], tags: [], forbids: [].}
- Get scheduled event cover Source Edit
proc getGuildWidget(guild_id, style: string): string {....raises: [ValueError], tags: [], forbids: [].}
- Gets a guild widget. https://discord.com/developers/docs/resources/guild#get-guild-widget-image-widget-style-options Source Edit
proc guildBanner(g: Guild; fmt = "png"): string {....raises: [], tags: [], forbids: [].}
- Get guild banner url Source Edit
proc iconUrl(e: Emoji; fmt = "png"; size = 128): string {....raises: [ValueError], tags: [], forbids: [].}
- Gets an emoji's url. Source Edit
proc `in`(x, y: set[PermissionFlags]): bool {....raises: [], tags: [], forbids: [].}
- Source Edit
proc len(component: MessageComponent): int {....raises: [ValueError], tags: [], forbids: [].}
- Returns number of items in an ActionRow or number of options in a menu Source Edit
proc memberAvatarUrl(g: Guild; m: Member; fmt = "png"): string {. ...raises: [ValueError], tags: [], forbids: [].}
- Gets a user's avatar url. If user does not have an avatar it will return default avatar of the user. Source Edit
proc memberBanner(g: Guild; m: Member; fmt = "png"): string {....raises: [], tags: [], forbids: [].}
- Get member banner url Source Edit
proc mention(parse, roles, users: seq[string]; ping: bool): AllowedMentions {. ...raises: [], tags: [], forbids: [].}
-
A constructor for AllowedMentions object that performs validation.
- Any value in parse is mutually exclusive with a field of the same name.
- To suppress all mentions, set parse to [].
- ping: set to true if you want a mentioned reply to ping the target.
proc newActionRow(components: varargs[MessageComponent]): MessageComponent {. ...raises: [], tags: [], forbids: [].}
- Creates a new action row which you can add components to. It is recommended to use this over raw objects since this does validation of the row as you add objects Source Edit
proc newButton(label, idOrUrl: string; style = Primary; emoji = Emoji(); disabled = false): MessageComponent {....raises: [], tags: [], forbids: [].}
-
Creates a new button.
- If the buttons style is NOT Link then it requires a customID
- If the buttons style is Link then it requires a url
proc newMenuOption(label: string; value: string; description = ""; emoji = Emoji(); default = false): SelectMenuOption {. ...raises: [], tags: [], forbids: [].}
-
Creates a new menu option for a select menu.
- label: The user facing value
- value: The dev facing value
- default: Whether this option is the default
proc newSelectMenu(custom_id: string; options: openArray[SelectMenuOption]; placeholder = ""; minValues, maxValues = 1; disabled = false): MessageComponent {. ...raises: [], tags: [], forbids: [].}
- Creates a new select menu. Options can be an empty seq but you MUST add options before adding it to the option row. min and max values is if you want users to be able to select multiple options Source Edit
proc `notin`(x, y: set[PermissionFlags]): bool {....raises: [], tags: [], forbids: [].}
- Source Edit
proc reference(m: Message): MessageReference {....raises: [], tags: [], forbids: [].}
- Source Edit
proc stripChannelMentions(m: Message): string {....raises: [ValueError], tags: [RootEffect], forbids: [].}
- 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: [RootEffect], forbids: [].}
- Strips all mentions. Source Edit
proc stripRoleMentions(m: Message): string {....raises: [ValueError, RegexError], tags: [RootEffect], forbids: [].}
- Strips out role mentions. Example: <@&123456890> to @1243456890 Source Edit
proc stripUserMentions(m: Message): string {....raises: [ValueError, RegexError], tags: [RootEffect], forbids: [].}
- Strips out user mentions. Example: <@1234567890> to @TheMostMysteriousUser#0000 Source Edit
proc waitForComponentUse(discord: DiscordClient; id: string): Future[Interaction] {. ...raises: [], tags: [], forbids: [].}
- Waits for a component to be used and returns the interaction. Data sent in the component can then be extracted. id is the ID that you used when creating the component Source Edit
proc waitForDeletion(discord: DiscordClient; msg: Message): Future[void] {. ...stackTrace: false, raises: [Exception], tags: [RootEffect], forbids: [].}
- Waits for a message to be deleted Source Edit
proc waitForInternal(discord: DiscordClient; event: static[DispatchEvent]; handler: proc): auto
-
Internal proc for wait for. This is done so the procs can properly be binded to
- The object returned would be a tuple that have the same parameter names in Events. e.g. if you were to waitFor message reaction add, it would be tuple[s: Shard, msg: Message, u: User, emj: Emoji, exists: bool] You can always find which type the parameter fields are by checking the Events object.
proc waitForRaw(discord: DiscordClient; event: string; handler: proc (data: JsonNode): bool): Future[JsonNode] {. ...stackTrace: false, raises: [Exception, ValueError], tags: [RootEffect], forbids: [].}
- This allows waiting for a dispatch event, except you can specify any string. This allows for handling events that aren't implemented in dimscord yet. The handler is ran before dimscord handles the event, so items might not be in cache. Use waitFor if you know the event you want to wait for Source Edit
proc waitForReaction(discord: DiscordClient; msg: Message; user: User = nil): Future[ Emoji] {....stackTrace: false, raises: [Exception, ValueError], tags: [RootEffect], forbids: [].}
-
Waits for a reaction to a message. Can optionally provide a user to only wait for a certain user.
Make sure you have message reaction intents, either one of giGuildMessageReactions or giDirectMessageReactions.
Source Edit proc waitForReply(discord: DiscordClient; to: Message): Future[Message] {. ...stackTrace: false, raises: [Exception, ValueError], tags: [RootEffect], forbids: [].}
- Waits for a message to reply to a message Source Edit
proc waitToJoinVoice(discord: DiscordClient; user: User; guildID: string): Future[ VoiceState] {....stackTrace: false, raises: [Exception, ValueError], tags: [RootEffect], forbids: [].}
- Waits for a user to join a voice channel in a guild. Source Edit
Macros
macro event(discord: DiscordClient; fn: untyped): untyped
- Sugar for registering an event handler. Source Edit
Templates
template addThreadMember(ch: GuildChannel; member: Member | User | string; reason = ""): Future[void]
- Adds a member to a thread. Source Edit
template beginPrune(g: Guild; days: range[1 .. 30] = 7; include_roles: seq[string] = @[]; compute_prune_count = true): Future[ void]
- Begins a guild prune. Source Edit
template bulkRegisterCommands(app: Application; commands: seq[ApplicationCommand]; guild_id = ""): Future[ seq[ApplicationCommand]]
- Overwrites existing commands slash command that were registered in guild. This means that only the commands you send in this request will be available in a specific guild Source Edit
template clearReactions(m: Message): Future[void]
- Remove all the reactions of a given message. Source Edit
template createChannel(g: Guild; name: string; kind = 0; parent_id, topic, rtc_region = none string; nsfw = none bool; position, video_quality_mode = none int; default_sort_order, default_forum_layout = none int; available_tags = none seq[ForumTag]; default_reaction_emoji = none DefaultForumReaction; rate_limit_per_user = none range[0 .. 21600]; bitrate = none range[8000 .. 128000]; user_limit = none range[0 .. 99]; permission_overwrites = none seq[Overwrite]; reason = ""): Future[ GuildChannel]
- Creates a channel. Source Edit
template createInvite(ch: GuildChannel; max_age = 86400; max_uses = 0; temporary, unique = false; target_user = none string; target_user_id, target_application_id = none string; target_type = none InviteTargetType; reason = ""): Future[ Invite]
- Creates an instant channel invite. Source Edit
template createStageInstance(ch: GuildChannel; topic: string; reason = ""; privacy = int plGuildOnly): Future[StageInstance]
- Create a stage instance. Source Edit
template deferResponse(i: Interaction; ephemeral, hide = false): Future[void]
-
Defers the response/update to an Interaction.
- You must use followup() or edit() after calling defer().
- Set ephemeral to true to make the Interaction ephemeral.
- Set hide to true to hide the "X is thinking..." state of the bot.
template delete(apc: ApplicationCommand; guild_id = ""): Future[void]
- Delete slash command for a specific application, guild_id is optional. Source Edit
template delete(gse: GuildScheduledEvent; reason = ""): Future[void]
- Delete a scheduled event in guild. Source Edit
template delete(i: Interaction; message_id = "@original"): Future[void]
- Deletes an Interaction Response or Followup Message Source Edit
template deleteChannel(ch: SomeChannel; reason = ""): Future[void]
- Deletes or closes a channel Source Edit
template deleteEmoji(g: Guild; e: Emoji; reason = ""): Future[void]
- Deletes a guild emoji. Source Edit
template deleteIntegration(integ: Integration; reason = ""): Future[void]
- Deletes a guild integration. Source Edit
template deleteRole(g: Guild; r: Role): Future[void]
- Deletes a guild role. Source Edit
template deleteRule(g: Guild; amr: AutoModerationRule): Future[void]
- deletes automod rule Source Edit
template deleteStageInstance(si: StageInstance | string; reason = ""): Future[ void]
- Delete the stage instance. Source Edit
template deleteWebhook(w: Webhook | string; reason = ""): Future[void]
- Deletes a webhook. Source Edit
template edit(apc: ApplicationCommand; name, desc = ""; name_localizations, description_localizations = none Table[string, string]; default_member_permissions = none PermissionFlags; options: seq[ApplicationCommandOption] = @[]): Future[ ApplicationCommand]
-
Modify slash command for a specific application.
- guild_id - Optional
- name - Optional Character length (3 - 32)
- descripton - Optional Character length (1 - 100)
template edit(ch: GuildChannel; name, parent_id, topic, rtc_region = none string; default_auto_archive_duration, video_quality_mode = none int; flags = none set[ChannelFlags]; available_tags = none seq[ForumTag]; default_reaction_emoji = none DefaultForumReaction; default_sort_order, default_forum_layout = none int; rate_limit_per_user = none range[0 .. 21600]; default_thread_rate_limit_per_user = none range[0 .. 21600]; bitrate = none range[8000 .. 128000]; user_limit = none range[0 .. 99]; position = none int; permission_overwrites = none seq[Overwrite]; nsfw = none bool; reason = ""): Future[GuildChannel]
- Modify a guild channel. Source Edit
template edit(g: Guild; gse: GuildScheduledEvent; name, start_time, image = none string; channel_id, end_time, desc = none string; privacy_level = none GuildScheduledEventPrivacyLevel; entity_type = none EntityType; entity_metadata = none EntityMetadata; status = none GuildScheduledEventStatus; reason = ""): Future[ GuildScheduledEvent]
- Update a scheduled event in a guild. Read more: https://discord.com/developers/docs/resources/guild-scheduled-event#modify-guild-scheduled-event-json-params Source Edit
template edit(g: Guild; lvl: MFALevel; reason = ""): Future[MFALevel]
- Modify Guild MFA Level, requiring guild ownership. Source Edit
template edit(g: Guild; name, description, region, afk_channel_id, icon = none string; discovery_splash, owner_id, splash, banner = none string; system_channel_id, rules_channel_id = none string; preferred_locale, public_updates_channel_id = none string; verification_level, default_message_notifications = none int; system_channel_flags = none int; explicit_content_filter, afk_timeout = none int; features: seq[string] = @[]; premium_progress_bar_enabled = none bool; reason = ""): Future[ Guild]
-
Modifies a guild. Icon needs to be a base64 image. (See: https://nim-lang.org/docs/base64.html)
Read more at: https://discord.com/developers/docs/resources/guild#modify-guild
Source Edit template edit(i: Interaction; content = none string; embeds = newSeq(); allowed_mentions = none AllowedMentions; attachments = newSeq(); files = newSeq(); components = newSeq(); message_id = "@original"): Future[ Message]
-
Edit an interaction response. You can use this to modify original interaction or followup message.
- message_id can be @original
template edit(m: Message; content = ""; embeds: seq[Embed] = @[]; attachments: seq[Attachment] = @[]; components: seq[MessageComponent] = @[]; files: seq[DiscordFile] = @[]; tts = false; flags = none int): Future[ Message]
- Edits a Message. Source Edit
template editRule(g: Guild; amr: AutoModerationRule; event_type = none int; name = none string; trigger_type = none ModerationTriggerType; trigger_metadata = none tuple[keyword_filter: seq[string], presets: seq[int]]; actions = none seq[ModerationAction]; enabled = none bool; exempt_roles, exempt_channels = none seq[string]; reason = ""): Future[ AutoModerationRule]
- Edits an automod rule. event_type is gonna be 1 for SEND_MESSAGE Source Edit
template editStageInstance(si: StageInstance | string; topic = none string; privacy = none int; reason = ""): Future[ StageInstance]
- Modify a stage instance. Source Edit
template followup(i: Interaction; content = ""; embeds: seq[Embed] = @[]; components: seq[MessageComponent] = @[]; attachments: seq[Attachment] = @[]; files: seq[DiscordFile] = @[]; allowed_mentions = none AllowedMentions; tts, ephemeral = false): Future[Message]
-
Follow-up to an Interaction.
- Use this function when sending messages to acknowledged Interactions.
template getAuditLogs(g: Guild; user_id, before = ""; action_type = -1; limit: range[1 .. 100] = 50): Future[AuditLog]
- Get guild audit logs. The maximum limit is 100. Source Edit
template getCommand(app: Application; guild_id = ""; command_id: string): Future[ ApplicationCommand]
- Get a single slash command for a specific Application, guild_id is optional. Source Edit
template getCommands(app: Application; guild_id = ""; with_localizations = false): Future[ seq[ApplicationCommand]]
- Get slash commands for a specific Application, guild_id is optional. Source Edit
template getEventUsers(gse: GuildScheduledEvent; limit = 100; with_member = false; before, after = ""): Future[ seq[GuildScheduledEventUser]]
- Gets the users and/or members that were subscribed to the scheduled event. Source Edit
template getIntegrations(g: Guild): Future[seq[Integration]]
- Gets a list of guild integrations. Source Edit
template getInvites(ch: GuildChannel): Future[seq[Invite]]
- Gets a list of a channel's invites. Source Edit
template getInvites(g: Guild): Future[seq[InviteMetadata]]
- Gets guild invites. Source Edit
template getMembers(g: Guild; limit: range[1 .. 1000] = 1; after = "0"): Future[ seq[Member]]
- Gets a seq of a guild's members. Source Edit
template getMessage(ch: SomeChannel; message_id: string): Future[Message]
- Get a channel message. Source Edit
template getMessages(ch: SomeChannel; around, before, after = ""; limit: range[1 .. 100] = 50): Future[seq[Message]]
- Gets channel messages. Source Edit
template getPins(ch: SomeChannel): Future[seq[Message]]
- Get channel pins. Source Edit
template getPruneCount(g: Guild; days: int): Future[int]
- Gets the prune count. Source Edit
template getReactions(m: Message; emoji: string; before, after = ""; limit: range[1 .. 100] = 25): Future[seq[User]]
- Get all user message reactions on the emoji provided. Source Edit
template getRegions(g: Guild): Future[seq[VoiceRegion]]
- Gets a guild's voice regions. Source Edit
template getResponse(i: Interaction; message_id = "@original"): Future[Message]
- Get the response (Message) to an Interaction Source Edit
template getRule(g: Guild; rule_id: string): Future[AutoModerationRule]
- Get a Guild's specific AutoMod Rule Source Edit
template getRules(g: Guild): Future[seq[AutoModerationRule]]
- Get a Guild's current AutoMod Rules Source Edit
template getScheduledEvent(g: Guild; event_id: string; with_user_count = false): Future[ GuildScheduledEvent]
- Get a scheduled event in a guild. Source Edit
template getScheduledEvents(g: Guild): Future[seq[GuildScheduledEvent]]
- Get all scheduled events in a guild. Source Edit
template getThreadMember(ch: GuildChannel; user: User | string): Future[ ThreadMember]
- Get a thread member. Source Edit
template getThreadMembers(ch: GuildChannel): Future[seq[ThreadMember]]
- List thread members. Note: This endpoint requires the GUILD_MEMBERS Privileged Intent if not enabled on your application. Source Edit
template getWebhooks(ch: GuildChannel): Future[seq[Webhook]]
- Gets a list of a channel's webhooks. Source Edit
template getWebhooks(g: Guild): Future[seq[Webhook]]
- Gets a list of a channel's webhooks. Source Edit
template joinThread(ch: GuildChannel): Future[void]
- Join thread. Source Edit
template leaveThread(ch: GuildChannel): Future[void]
- Leave thread. Source Edit
template newThread(ch: GuildChannel; name: string; auto_archive_duration = 60; kind = ctGuildPrivateThread; invitable = none bool; reason = ""): Future[GuildChannel]
- Starts a new thread without any message. Source Edit
template preview(g: Guild): Future[GuildPreview]
- Gets guild preview. Source Edit
template registerCommand(app: Application; name, description: string; name_localizations, description_localizations = none Table[string, string]; kind = atSlash; guild_id = ""; dm_permission = true; default_member_permissions = none PermissionFlags; options: seq[ApplicationCommandOption] = @[]): Future[ ApplicationCommand]
-
Create a guild slash command.
- guild_id Optional
- name - Character length (3 - 32)
- descripton - Character length (1 - 100)
NOTE: Creating a command with the same name as an existing command for your application will overwrite the old command.
Source Edit template removeMember(g: Guild; m: Member; reason = ""): Future[void]
- Removes a guild member. Source Edit
template removeReaction(m: Message; emoji: string; user_id = "@me"): Future[void]
- Removes the user's or the bot's message reaction to a Discord message. Source Edit
template removeReactionEmoji(m: Message; emoji: string): Future[void]
- Remove all the reactions of a given emoji. Source Edit
template removeRole(mb: Member; r: Role; reason = ""): Future[void]
- Removes a member's role. Source Edit
template searchMembers(g: Guild; query = ""; limit: range[1 .. 1000] = 1): Future[ seq[Member]]
- Search for guild members. Source Edit
template send(ch: SomeChannel; content = ""; tts = false; nonce: Option[string] or Option[int] = none(int); files: seq[DiscordFile] = @[]; embeds: seq[Embed] = @[]; attachments: seq[Attachment] = @[]; allowed_mentions = none AllowedMentions; message_reference = none MessageReference; components = newSeq[MessageComponent](); sticker_ids = newSeq[string]()): Future[Message]
-
Sends a Discord message.
- nonce This can be used for optimistic message sending
template sendModal(i: Interaction; response: InteractionCallbackDataModal): Future[ void]
- Create an interaction response which is a modal. Source Edit
template setNickname(g: Guild; nick: string; reason = ""): Future[void]
-
Sets the current user's guild nickname
- Set nick to "" to reset nickname.
template startThread(m: Message; name: string; auto_archive_duration: range[60 .. 10080]; reason = ""): Future[ GuildChannel]
-
Starts a public thread.
- auto_archive_duration Duration in mins. Can set to: 60 1440 4320 10080
template suggest(i: Interaction; choices: seq[ApplicationCommandOptionChoice]): Future[ void]
- Create an interaction response which is an autocomplete response. Source Edit
template update(i: Interaction; content = ""; embeds: seq[Embed] = @[]; flags: set[MessageFlags] = {}; attachments: seq[Attachment] = @[]; components: seq[MessageComponent] = @[]; allowed_mentions = default(AllowedMentions); tts = none bool): Future[ void]
-
Updates the message on which an Interaction was received on.
- This acknowledges an Interaction.
template waitFor(discord: DiscordClient; event: static[DispatchEvent]; handler: untyped): auto
-
Allows you to define a custom condition to wait for. This also returns the object that passed the condition.
- Note: some event objects may be same as the event name e.g. GuildMembersChunk, you can write this as deGuildMembersChunk instead of having to write DispatchEvent.GuildMembersChunk.
- The object returned would be a tuple that have the same parameter names in Events. e.g. if you were to waitFor MessageReactionAdd, it would be tuple[s: Shard, msg: Message, u: User, emj: Emoji, exists: bool] You can always find which type the parameter fields are by checking the Events object.
See also:
Source Edit