Represents a client connection to the Discord API and Gateway.
Client
Extends
Emitter
Parameters
options (object?)
The options to use for the client.
Name |
Description |
options.allowedMentions object?
|
The default allowed mentions to use when sending messages.
|
options.intents Intents?
|
The intents to use when connecting to the gateway.
|
options.apiVersion number?
|
The REST API version to use for requests.
|
options.gatewayVersion number?
|
The gateway version to use for interacting with Discord's gateway.
|
options.shard boolean?
|
Whether or not to shard the bot. Must be explicitly enabled for large bots.
|
options.shardCount number?
|
The amount of shards to connect to. This should usually never be used.
|
Instance Members
Represents the internal cache of the client.
cache
Whether or not sharding is handled for this client.
sharded
Type:
boolean
The default allowed mentions to use whenever the client sends a message.
allowedMentions
Type:
object
The intents to use when connecting to the gateway.
intents
Type:
Intents
Whether or not the client has made at least one heartbeat with the websocket yet.
loggedIn
Type:
boolean
The HTTPClient the client uses to make HTTP requests.
http
Type:
HTTPClient
The websocket the client uses to interact with the gateway.
ws
Type:
Websocket
Returns an array of websockets corresponding to the bot's shards.
Only valid for sharded clients.
shards
Type:
Websocket?
Returns this client's User ID.
id
Type:
string?
Gets the requested API version the client will use.
apiVersion
Type:
number
Gets the requested gateway version the client will use.
gatewayVersion
Type:
number
Returns the bot's latency in milliseconds.
If this bot is sharded, this returns the average shard latency.
latency
Type:
number?
Returns an array of numbers corresponding to it's shard's latency.
Only valid for sharded clients.
latencies
Type:
Array<number>?
Starts the bot.
Parameters
token (string)
The token to use to login into the gateway.
Logs into Discord and starts the bot.
Parameters
token (string)
The authentication token given by Discord.
Tries to get a user from the internal cache.
Parameters
id (string)
The id of the user to find.
Returns
User?
:
The found user.
Tries to get a channel from the internal cache.
Parameters
id (string)
The id of the guild to find.
Returns
Guild?
:
The found guild.
Tries to get a channel from the internal cache.
Parameters
id (string)
The id of the channel to find.
Returns
Channel?
:
The found channel.
Tries to get a role from the internal cache.
Parameters
id (string)
The id of the role to find.
Returns
Role?
:
The found role.
Gets all of the users currently stored in the internal cache.
users
Type:
Array<User>
Gets all of the channels currently stored in the internal cache.
channels
Type:
Array<Channel>
Gets all of the guilds currently stored in the internal cache.
guilds
Type:
Array<Guild>
Gets all of the roles currently stored in the internal cache.
roles
Type:
Array<Role>
Fetches a guild via ID from the Discord API.
Parameters
id (string)
The ID of the guild to fetch.
Returns
Guild
:
The guild object.
Creates a guild.
Parameters
name (string)
The name of the guild.
Returns
Guild
:
The guild created.
▸
onSlashCommand(command, callback)
Listens for when a slash command is invoked.
Callback can take zero, one (ctx: SlashContext)
parameter,
or two (ctx: SlashContext, options: Object)
parameters.
You must supply a slash command or it's ID in this case.
You can query slash commands by it's name via Client#getSlashCommandNamed
.
Parameters
callback (function)
The callback of the command.
▸
createSlashCommand(command, guilds, callback)
Creates a global slash command.
You can also create guild slash commands here, too.
Parameters
guilds ((Guild? | string | Array<(Guild | string)>))
The guild or array of guilds that this slash command will be created in. Leave blank for global.
callback (function?)
The callback for when this command is invoked.
Returns
SlashCommand
:
The slash command created.
Related
Client#onSlashCommand
The base class that emits events and manages their callbacks.
Client extends this class.
Emitter
Instance Members
Adds a strict listener to your emitter.
Parameters
event (string)
The event to listen for.
callback (function)
The callback for when the event is emitted.
Listens for your event to be emitted only once.
Parameters
event (string)
The event to listen for.
callback (function)
The callback for when the event is emitted.
▸
listen(event, callback)
Adds a separate listener to your emitter.
Unlike Emitter#on, there can be multiple instances of these listeners.
Parameters
event (string)
The event to listen for.
callback (function)
THe callback for when the event is emitted.
▸
emit(event, parameters)
Emits an event.
emit(event:
string, parameters: ...any)
Parameters
event (string)
The event to emit.
parameters (...any)
The parameters to pass into the events' callbacks.
▸
collect(event, options)
Collects the payloads of events that are emitted.
Parameters
event (string)
The event to listen for.
options (object?
= {}
)
The options to use when collecting.
Name |
Description |
options.timeout number?
|
The amount of time in milliseconds to collect for.
|
options.check function?
|
The check function for each event collected.
|
options.limit number?
|
The maximum amount of events to collect.
|
options.suppress boolean?
(default true )
|
Whether or not to suppress timeout errors.
|
▸
waitFor(event, options)
Waits for an event to be emitted, then returns the payload.
Parameters
event (string)
The event to wait for to emit.
options (object?
= {}
)
The options to use when waiting.
Name |
Description |
options.check function?
|
The check function for the event.
|
options.timeout number?
|
The maximum amount of time to wait for the event to be emitted.
|
Returns
any
:
The event payload.
A sequentializing utility class used to efficiently manage promises.
Queue
Instance Members
The amount of queued promises.
count
Waits for the last promise to complete and queues a new one.
Returns
Promise<any>?
:
The promise that was queued.
Unlocks the queue for the next promise.
shift()
Discord enumerations.
enums
Represents a row of components.
ActionRow
Extends
Component
Instance Members
An array of components this row has.
components
Type:
Array<Component>
▸
addComponent(component)
Adds a component to this row.
Parameters
Turns this row into raw JSON data to be sent to Discord.
Returns
object
:
The data to send to Discord.
Represents a button component.
Button
Extends
Component
Instance Members
The base class that represents a Discord message component.
Component
Static Members
Turns raw Discord data into a Component.
Parameters
data (object)
The raw JSON data.
Returns
Component
:
The component made from the raw data.
Instance Members
The type of this component.
type
Type:
number
Related
enums.ComponentType
The custom ID of this component.
id
Type:
string
Returns
JSON
:
Returns a JSON object with the type and custom_id keys
Represents the entire components of a message.
Components
Instance Members
Returns a copy of this instance.
Returns
Components
:
The copy.
Adds an ActionRow to the components.
Parameters
components (...Component)
The components to add to the row.
▸
addComponent(component)
Adds a component while automatically wrapping.
Parameters
Iterates over all of the components.
ActionRows are not included here.
components()
Returns the visible component at a certain index.
Parameters
index (number)
The index to view.
Returns
Component?
:
The component at the given index, if any.
Turns this into a JSON object.
Returns
object
:
The raw JSON data.
Represents a slash command.
SlashCommand
Parameters
name (string)
The name of the slash command.
options (object?)
The options to use when creating the command.
Static Members
Creates a slash command object from JSON.
Parameters
options (Object
= {}
)
The JSON object to provide.
Name |
Description |
options.id any
|
|
options.application_id any
|
|
options.name any
|
|
options.description any
|
|
options.options any
(default [] )
|
|
options.default_permission any
(default true )
|
|
Returns
SlashCommand
:
Instance Members
Sets the name of the slash command.
Parameters
name (string)
The slash command name.
Returns
SlashCommand
:
▸
setDescription(description)
Sets the description of the slash command.
Parameters
description (string)
The slash command description.
Returns
SlashCommand
:
Adds an option to the slash command.
Parameters
option (Object)
The option to add to the slash command.
Returns
SlashCommand
:
Returns a JSON object representing this slash command.
Returns
Object
:
Represents a slash command option.
SlashCommandOption
Instance Members
Adds a choice for the user to pick.
Parameters
name (string)
The choice name shown to the user.
value (string)
The choice value given to the bot.
Returns
SlashCommandOption
:
Returns a JSON object representing this slash command option.
Returns
Object
:
If the option is optional.
optional
Type:
boolean
Represents the context for a slash command interaction.
SlashContext
Instance Members
▸
respond(content, options)
Responds to the interaction.
Parameters
content (string)
The content to send.
options (Object)
The send options.
Returns
Message
:
Sends a message (follow-up) to the channel.
Parameters
content (string)
The content to send.
options (Object)
The send options.
Returns
Message
:
Utility constants to aid in providing allowed mentions for messages.
AllowedMentions
Static Members
Allowed mentions with all mentions enabled.
Returns
object
:
Allowed mentions with all mentions disabled.
Returns
object
:
Allowed mentions with only user mentions enabled.
Returns
object
:
Represents a Discord asset or image.
Asset
Instance Members
The hash of the asset.
hash
Whether or not the asset is an animated asset.
animated
The URL of this asset.
url
Gets the asset of the URL, with a bit of customization.
Parameters
options (object)
The URL options for the url.
Name |
Description |
options.format any
|
|
options.size any
|
|
options.staticFormat any
|
|
Returns
string
:
The URL of the asset.
The base class that represents a bitfield.
Bitfield
Static Members
▸
fromObject(object, mapping)
From mapping keys to their bit values,
this will create a Bitfield out of them.
Parameters
object (object?
= {}
)
The object to use.
mapping (object
= {}
)
The mapping to use.
Returns
Bitfield
:
The created bitfield.
Instance Members
The integer value of the current bits.
value
Type:
number
Represents a general Discord channel.
This could be a text channel, DM channel, voice channel, etc.
Channel
Extends
DiscordObject
Instance Members
The channel's type.
type
Type:
number
Related
enums.ChannelType
Represents the client as a user.
Because the client has accesse to it's own information,
it will have access to more properties than any other user.
ClientUser
Extends
User
Instance Members
Whether or not 2-factor authentication is enabled on this account.
mfaEnabled
Type:
boolean?
The chosen language option.
locale
Type:
string?
Whether or not this account has a verified email.
verified
Type:
boolean?
Represents a color.
Color
Parameters
value (number?)
The decimal representation of this color.
Represents a Discord object with a snowflake.
DiscordObject
Instance Members
The date and time that this object was created.
createdAt
Type:
Date
The ID of this object.
id
Type:
string
Represents embedded content of a Discord message.
You can also construct this class to send your own embeds.
Embed
Parameters
data (object?)
The raw JSON data, usually from Discord, to construct this embed with.
Instance Members
The type of this embed. Usually 'rich'.
type
Type:
string
The author for this embed.
author
Type:
object?
The thumbnail for this embed.
thumbnail
Type:
object?
The large image for this embed.
image
Type:
object?
The video for this embed.
Rich embeds do not have this property.
video
Type:
object?
The embed's provider.
Rich embeds do not have this property.
provider
Type:
object?
The fields for this embed.
There can be up to 25 of these.
fields
Type:
Array<object>?
The embed's title.
title
Type:
string?
The embed's description.
description
Type:
string?
The title's URL.
url
Type:
string?
The timestamp shown on the embed.
timestamp
Type:
Date?
The color of the embed.
color
Type:
Color?
Sets and overwrites the title for this embed.
Parameters
title (string)
The title text.
url (string?)
The URL that the title leads to.
▸
setDescription(description)
Sets and overwrites the description for this embed.
setDescription(description:
string)
Parameters
description (string)
The description text.
▸
appendDescription(description)
Adds a new line with text to the description.
appendDescription(description:
string?)
Parameters
description (string?)
The text to add to the description.
Sets the title's URL.
Parameters
url (string)
The new URL of this embed.
Changes the color of this embed.
Parameters
color (Color)
The new color of the embed.
▸
setTimestamp(timestamp)
Changes the timestamp shown on this embed.
setTimestamp(timestamp:
Date?)
Parameters
timestamp (Date?)
The new timestamp for this embed.
▸
addField(name, value, inline)
Adds a field to this embed.
Parameters
name (string)
The name [title] of this field.
value (string)
The value [description] of this field.
inline (boolean?)
Whether or not this field is inline or not.
Removes a field from this embed.
Parameters
index (number)
The index of the field to remove, starting from 0.
▸
setField(index, name, value, inline)
Overwrites an already existing field.
Parameters
index (number)
The index of the field to overwrite.
name (string)
The new name [title] of this field.
value (string)
The new value [description] of this field.
inline (boolean?)
Whether or not this field is inline or not.
▸
spliceField(index, remove, name, value, inline)
Splices the embed fields.
Parameters
index (number)
The index to start splicing from.
remove (number)
The amount of fields to remove at this index.
name (string)
The name [title] of this field.
value (string)
The value [description] of this field.
inline (boolean?)
Whether or not this field is inline or not.
▸
insertField(index, name, value, inline)
Inserts a new field at the given index.
Parameters
index (number)
The index to insert the field at.
name (string)
The name [title] of this field.
value (string)
The value [description] of this field.
inline (boolean?)
Whether or not this field is inline or not.
Removes all of the fields in this embed.
clearFields()
Pops a field from this embed.
Returns
object?
:
The field that was popped.
Shifts a field from this embed.
shiftField()
▸
swapField(index, otherIndex)
Swaps a field with another one.
Parameters
index (number)
The index to swap.
otherIndex (number)
The other index to swap with.
Finds a field in this embed based on it's name.
Parameters
name (string)
The name [title] of the field to find.
Returns
object?
:
The field found, if any.
▸
setAuthor(name, iconURL, url)
Sets and overwrites thie embed's author.
Parameters
name (string)
The author text.
iconURL (string?)
The author's icon URL.
url (string?)
The URL the author leads to.
Sets the thumbnail of this embed.
Parameters
url (string?)
The image URL of the new thumbnail.
Sets the large image of this embed.
Parameters
url (string?)
The image URL of the new image.
Turns this embed into a JSON object.
Note: This only takes into account rich embeds.
Returns
object
:
Represents a Discord server.
In Discord's API, servers are referred to as "guilds".
Guild
Extends
DiscordObject
Instance Members
The name of this guild.
name
Type:
string
The default voice region of this guild.
region
Type:
string
The asset that represents this guild's icon.
icon
Type:
Asset
The asset that represents this guild's splash image.
splash
Type:
Asset
An array of members that are in the guild.
members
Type:
Array<Member>
An array of the guild's channels.
channel
Type:
Array<Channel>
An array of the guild's roles.
roles
Type:
Array<Role>
Fetches members from Discord and fills the cache.
fillMembers()
Gets a member by it's ID using the internal cache.
Parameters
id (string)
The ID of the member.
Returns
Member?
:
The found member, if any.
▸
getMemberNamed(query, options)
Gets a member by it's name using the internal cache.
Parameters
query (string)
The name or nickname of the member.
options (object
= {}
)
The options for querying.
Name |
Description |
options.caseInsensitive any
(default false )
|
|
Returns
Member?
:
The found member, if any.
Gets a role by it's ID using the internal cache.
Parameters
id (string)
The ID of the role.
Returns
Role?
:
The found role, if any.
▸
createSlashCommand(command, callback)
Creates a slash command in this guild.
Parameters
callback (function?)
The temporary callback for when the command is invoked.
Returns
SlashCommand?
:
The created slash command, if successful.
Represents a channel that's present in a guild.
GuildChannel
Extends
Channel
Instance Members
The guild this channel is in.
guild
Type:
Guild?
The position of the channel.
position
Type:
number
The name of the channel.
name
Type:
string
Represents an interaction with a user.
This is sent when a slash command is invoked, or a component was pressed.
Interaction
Extends
DiscordObject
Instance Members
The interaction token to send to Discord.
token
Type:
string
This is always 1.
version
Type:
integer
The ID of the application (user) that received the interaction.
This is usually always your bot's ID.
applicationID
Type:
string
The type of interaction this is.
type
Type:
integer
Related
enums.InteractionType
The interaction data, such as the options provided in the interaction.
data
Type:
object?
The channel this interaction was sent in.
channel
Type:
(TextChannel? | DMChannel)
The guild this interaction was sent in.
guild
Type:
Guild?
The interaction message.
message
Type:
Message
The user that made this interaction.
author
Type:
(User | Member)
▸
respond(content, options, __overwrites)
Responds to the interaction.
respond(content:
string?, options: options?, __overwrites: any):
Message?
Parameters
content (string?)
The content of the message.
Returns
Message?
:
The message sent, if there was one.
Represents a guild member.
Member
Extends
User
Instance Members
Gets a User representation of this member.
Returns
User
:
The resulting User object of this member.
The nickname of the member, if any.
nick
Type:
string?
The date and time the member joined at.
joinedAt
Type:
Date
Represents a Discord message.
Message
Extends
DiscordObject
Instance Members
The user or member that sent this message.
author
Type:
(Member | User)
Whether or not this message had TTS enabled.
tts
Type:
boolean
The raw text content of the message.
content
Type:
string
Whether or not this message mentioned everyone.
mentionsEveryone
Type:
boolean
Whether or not this message is pinned.
Only valid for messages sent in TextChannels.
pinned
Type:
boolean?
The type enumeration of the message.
type
Type:
number
Related
enums.MessageType
The last time this message was edited.
editedAt
Type:
Date?
The channel that this message was sent in.
channel
Type:
(TextChannel | DMChannel)
The guild that this message was sent in, if any.
guild
Type:
Guild?
Edits this message.
Parameters
content (string)
The new contents of the message.
Returns
Message
:
The updated
Message
object.
▸
reply(content, options)
Replies to this message.
Parameters
content (string)
The contents of the message.
Returns
Message
:
The sent
Message
.
Deletes this message.
Parameters
delay (number?
= 0
)
How long to way before deleting the message.
Returns
boolean
:
"true" if the message was successfully deleted.
Adds a reaction to this message.
Parameters
Builds a raw message object out of the given content and options.
MessageBuilder
Parameters
destination (any)
The destination of the message.
content (string?)
The contents of the message.
options (object?)
The message options, such as embeds and files.
type (string?)
The type of message to send.
extra (...any)
Extra data to use when building the message.
Instance Members
The ID of the destination.
destinationID
Type:
string
The ID of the reference of the message, if any.
referenceID
Type:
string?
The options for sending this message.
options
Type:
object
The extra contextual data for sending this message.
context
Type:
object
The actual raw payload to use when requesting to Discord.
payload
Type:
object
The files to attach to the message.
files
Type:
Array<any>
The type of the message, provided in the constructor.
type
Type:
string
Actually builds the message.
build()
Sends the built payload to Discord.
Returns
Message?
:
The message, if successfully sent.
Represents any emoji with minimal information.
PartialEmoji
Instance Members
The ID of this emoji.
id
Type:
string?
The name of this emoji.
name
Type:
string
Whether this emoji requires colons.
requireColons
Type:
boolean
Whether or not this emoji is managed.
managed
Type:
boolean
Whether or not this is an animated emoji.
animated
Type:
boolean
Whether or not this emoji can be used by the bot.
available
Type:
boolean
Whether or not this emoji is a raw unicode emoji.
unicode
Type:
boolean
The asset this emoji uses.
image
Type:
Asset?
Turns this emoji into one that displays in Discord.
Returns
string
:
The formatted emoji string.
Turns this emoji into a raw JSON object to be sent to Discord.
Returns
object
:
The raw emoji object.
Represents a reaction on a Discord message.
Reaction
Instance Members
The amount of users who reacted with this reaction.
count
Type:
number?
Whether or not the client has reacted with this reaction.
me
Type:
boolean?
The message this reaction is from.
message
Type:
Message?
The channel this reaction is from.
channel
Type:
Channel?
The guild this reaction is from.
guild
Type:
Guild?
Gets the users that reacted with this reaction.
Parameters
options (object?
= {}
)
The options to use.
Name |
Description |
options.after string?
|
Only retrieve reactions after this snowflake.
|
options.limit number?
|
The maximum amount of reactions to retrieve.
|
Returns
Array<User>
:
The users that reacted.
Represents a Discord role.
Role
Extends
DiscordObject
Instance Members
The guild that has this role.
guild
Type:
Guild
The name of the role.
name
The color of the role.
color
Type:
Color
Whether or not the role is hoisted or not.
hoist
Type:
boolean
The position of the role.
position
Type:
number
The permissions of the role.
permissions
Type:
Permissions
Whether or not the role is mentionable.
mentionable
Type:
boolean
Whether or not the role is the guild's nitro boosting role.
premium
Type:
boolean
The ID of the bot that represents this role. undefined if this isn't a bot role.
botID
Type:
string?
The ID of the integration that manages this role. undefined if no integration manages this role.
integrationID
Type:
string?
Gets a list of the members in the role's guild that are assigned to the role.
members
Represents a map of snowflakes to their DiscordObjects (ones that have parameter id
).
This ensures that only one copy of any snowflake is present in this map.
SnowflakeSet
Extends
Map
Instance Members
Adds objects to the set.
push(objects: ...any)
Parameters
objects (...any)
The object(s) to add.
Filters the set based on a function.
Parameters
predicate (function)
The filtering function to use.
Returns
Array<DiscordObject>
:
An array of the filtered objects.
Related
Array#filter
Finds the first object in the set that meets the predicate, and returns it.
Parameters
predicate (function)
The check function to use.
Returns
DiscordObject?
:
The object found, if any.
Related
Array#find
Represents a text channel in a guild.
TextChannel
Extends
GuildChannel
Instance Members
The channel topic of this channel.
topic
Type:
string?
Whether or not this channel is marked as NSFW.
nsfw
Type:
boolean
The last message sent in this channel, if any.
lastMessage
Type:
Message?
Tries to get a message from the internal cache via ID.
Parameters
id (string)
The ID of the message.
Returns
Message?
:
The found message, if any.
Sends a message in this channel.
Parameters
content (string?)
The contents of the message to send.
Returns
Message?
:
The message, if successfully sent.
Represents a Discord user.
User
Extends
DiscordObject
Instance Members
The user's username.
name
Type:
string
The user's discriminator.
discriminator
Type:
string
The user's avatar asset.
avatar
Type:
Asset
Whether or not the user is a bot account.
bot
Type:
boolean
Whether or not the user is an official system account.
system
Type:
boolean
Returns the user's full tag in the name#discrim format.
tag
Type:
string
Returns the mention of the user.
mention
Type:
string
Represents the user's nickname or friend nickname.
This is currently always the same as User#name.
displayName
Type:
string
Whether or not the user's avatar is animated.
avatarAnimated
Type:
boolean
The user's avatar URL.
avatarURL
Type:
string
The user's avatar URL with customization options.
Parameters
options (object?)
The options for the URL.
Returns
string
:
The user's avatar URL.
Represents a bot using the commands plugin.
This class extends Client.
Bot
Extends
Client
Instance Members
Adds the default listeners to the bot.
addDefaultListeners()
Parses a prefix from a message. (if found)
Parameters
Returns
Promise<string?>
:
The prefix found in the message.
Gets a command by name.
Parameters
query (string)
The command query.
Returns
Command
:
The command found from the search.
Returns the parsed context of a message.
Parameters
Returns
Context
:
The parsed context of the message.
Invokes a command from a Context object.
Parameters
▸
command(options, callback)
Adds a command to the bot.
Parameters
options (Object)
The command options.
callback (function)
The command callback.
Gets the bot's flag prefix.
Parameters
Returns
string
:
The long flag prefix.
▸
getShortFlagPrefix(message)
Gets the bot's short flag prefix.
Parameters
Returns
string
:
The short flag prefix.
Represents a bot command.
Command
Instance Members
The name of the command.
name
The aliases this command has.
aliases
The cooldowns this command has.
cooldowns
The checks of this command.
checks
The arguments of this command.
args
The flags of this command.
flags
The parent command of this command.
This will only be present if the command is a subcommand.
parent
Returns the command's qualified name.
qualifiedName
Returns
string
:
Returns The parent command if there is one.
parents
Returns
Command?
:
Gets all the subcommands of this command.
commands
Returns
Command<Array>
:
The list of Subcommands
▸
command(options, callback)
Creates and adds a command object to the bot.
Parameters
options (Object)
The options to provide for the command.
callback (function)
The command's callback function.
Returns
Command
:
The resulting command.
Returns the formatted signature of the command.
Parameters
options (Object
= {}
)
The symbols to use while generating the signature.
Name |
Description |
options.required any
(default '<>' )
|
|
options.optional any
(default '[]' )
|
|
options.array any
(default '...' )
|
|
options.defaultIndicator any
(default '=' )
|
|
options.separator any
(default ' ' )
|
|
Returns
string
:
The signature of the command.
Returns the signature of the command.
signature
Returns
string
:
The signature of the command, which looks like a unix command signature.
Returns the usage of the command.
usage
Returns
string
:
The usage of command, which is the qualified name + the signaure
▸
getArguments(ctx, content)
Splits the content into two groups: arguments and flags.
Parameters
content (string)
The content of the message.
Returns
Promise<Array>
:
The array of arguments and flags.
▸
_parseArguments(ctx, content)
Parse arguments out of a string.
Parameters
content (string)
The content to parse arguments out of.
Returns
Promise<Object>
:
An object with argument name -> content.
▸
_parseFlags(ctx, content, flagPrefix, shortPrefix)
Parse flags out of a string.
Parameters
content (string)
The content of the message.
flagPrefix (string)
The prefix for long flags. (default: --)
shortPrefix (string)
The prefix for short flags. (default: -)
Returns
Promise<Object>
:
The parsed flags
▸
invoke(ctx, args, flags)
Calls the command function.
Parameters
args (Object)
The given arguments.
flags (Object)
The given flags.
On mobile, -- is usually replaced by an em dash. Here we reverse this.
Parameters
content (string)
The content to replace long dashes.
Returns
string
:
The replaced content.
Represents the context of a command.
This contains things such as the message, channel, and command the author invoked.
Context
Instance Members
The prefix used to invoke the context, escaping mentions.
For example <@12345678> becomes @User
cleanPrefix
Returns
string
:
The time the message to invoke the context was created at.
now
Type:
Date
The unix time the message to invoke the context was created at.
unix
Type:
number
▸
invoke(command, args, flags)
Invokes a command.
Parameters
command (command)
The command to invoke.
args (Object)
The arguments to provide.
flags (Object)
The flags to provide.
Reinvokes the command provided from the original message.
reinvoke()
Sends a message to the channel.
Parameters
content (string)
The content to send.
options (Object)
The options to provide.
Returns
Promise<Message>
:
▸
reply(content, options)
Sends an inline reply to the invoked message.
Parameters
content (string)
The content to reply with.
options (Object)
The options to provide.
Returns
Promise<Message>
:
The base converter class for the commands plugin.
Converter
Instance Members
Converts an argument to a specific class.
Parameters
argument (string)
The argument provided by the user.
A utility class that helps parse words out of a string.
new StringView(text: any, quotes: any)
Parameters
quotes (any
= defaultQuotes
)
Instance Members
The text buffer of the view.
text
Type:
string
The quote mapping of the view.
quotes
Type:
object
The current index the view is on.
index
Type:
number
The previous character parsed.
previous
Type:
string?
The length of the text.
end
Type:
number
Whether or not the view has finished parsing the string.
eof
Type:
boolean
The current character at the view's index.
buffer
Type:
string?
Reads one single character and returns it.
Returns
string?
:
The read character.
Rolls back to the previous index.
rollback()
Reads the text until the end and returns the read characters.
Returns
string
:
The rest of the text.
Reads until the next character is not a whitespace.
Returns
boolean
:
Whether or not a space was skipped.
Reads the next word, or words in quotes, and returns it.
Parameters
options (object
= {}
)
The options for parsing.
Name |
Description |
options.skipSpace any
(default false )
|
|
Returns
any
:
The parsed word.
Represents a reversed StringView.
No support for quotes here,
this was primarily made to get
a command from a string.
new BasicReverseStringView(text: any)
Parameters
General utility functions and classes.
utils
Static Members
Generates pages out of text.
Inspired by discord.py's pagination system.
BasePaginator
Paginator that supports force wrapping and multiple delimiters.
This should be used over BasePaginator.
Paginator
Extends
BasePaginator
Emulates Python's sum
function.
sum
Parameters
array (Array<any>)
The array of items to sum.
key (function?)
The key to use when calculating the sum.
Returns
any
:
The sum of the array.
Returns a promise that sleeps for the requested amount of time.
Parameters
milliseconds (number)
The amount of milliseconds to sleep for.
Returns
Promise
:
Generates a random number that has the given amount of bits.
Parameters
bits (number)
The amount of bits the number will have.
Returns
bigint
:
The generated number.
▸
maybePromise(func, args)
If the given function returns a Promise, return it.
Else, turn it into one and return it.
Parameters
args (...any)
The arguments to pass into the function.
Returns
Promise<any>
:
Parses an emoji string and returns the parsed object.
Parameters
emoji (string)
The emoji string to use. E.g. '<:blobpain:739614945045643447>'
Returns
object
:
The object with schema { name: string, id: ?string, animated, boolean }
▸
parseSnowflake(snowflake)
Retrieves when a snowflake was created at.
Parameters
snowflake (string)
The snowflake to use.
Returns
Date
:
The date that represents the snowflake.
indexOf, but for objects.
Provide a value, and this method will return it's key.
index(object:
object, value: any): any
Parameters
object (object)
The object to use.
value (any)
The value of the key.
Returns
any
:
The found key of the object.
▸
isSubclass(cls, checks)
Checks is a class is a subclass of the given class,
or any if given an array of classes.
isSubclass(cls: class, checks: (class |
Array<class>)):
boolean
Parameters
cls (class)
The class to compare with.
checks ((class | Array<class>))
The class to compare to. Can also be an array of classes.
Returns
boolean
:
If the class is indeed a subclass of the class(es).
▸
range(start, stop, step)
Simulates the range
method in Python.
This returns a generator. You can turn it into an array via [...range(...)]
For example, range(2, 10, 2) will return a generator [ 2, 4, 6, 8 ], but not 10.
Parameters
start (number)
The number to start with. Defaults to 0.
stop (number)
Represents when to stop generating.
step (number
= 1
)
The increment per iteration.
Similar to Python's built-in enumerate
method.
enumerate(gen: generator, start:
number)
Parameters
gen (generator)
The generator to use.
start (number
= 0
)
The starting number. Defaults to 0.
▸
regexEscape(literalString)
Escapes special regex characters from a pattern.
Parameters
literalString (string)
The string to escape.
Returns
string
:
The resulting escaped characters.
Gets the current process time in milliseconds.
This should be used over Date#getTime
.
time
Type:
number
Returns a [pseudo]random integer given the range.
Parameters
min (number)
The minimum number, inclusive.
max (number)
The maximum number, also inclusive.
Returns
number
:
The number chosen.