Message class

const message = new Message(data: Message, addon: Addon);

constructor

The constructor of the Message class requires two arguments. The first argument must be an instance of the Discord.js Message class which provides the data for the message. The second argument must be an instance of the Zyno Bot Addons Addon class which defines the addon where the message should be created for.

Properties

addon

An instance of the Zyno Bot Addons Addon class which defines the addon where the Message class was created for.

author

An instance of the Member class when the message was sent in a Discord server. When the message was sent in a DM channel, this will be an instance of the User class.

guild

When the message was sent in a Discord server, this will be an instance of the Guild class.

guildId

The id of the guild where the message was sent in or the id of the member who sent the message in case the message is a DM.

isMe

A boolean which defines whether the author of the message is the bot.

created

An instance of the built-in NodeJS Date class which represents the time when the message was sent.

createdTimestamp

A number which represents the timestamp of the time when the message was sent.

editable

A boolean which defines whether the message can be edited or not by the bot.

edited

An instance of the built-in NodeJS Date class which represents the time when the message was edited. When the message wasn't edited, this will result in a value of null.

editedTimestamp

A number which represents the timestamp of the time when the message was edited.

id

The id of the message as a Twitter snowflake.

attachments

An instance of the Save class which provides the attachments provided in the message.

Save<id, Attachment>

url

The url to the message.

channel

The channel where the message was sent in. This can be an instance of the TextChannel, ForumChannel, ThreadChannel, VoiceChannel, StageChannel, DirectoryChannel or DMChannel class.

channelId

The id of the channel where the message was sent in or the id of the member who sent the message in case the message is a DM.

deletable

A boolean which defines whether the bot is able to delete the message or not.

mentions

An instance of the Mentions class which provides the mentions in the message.

content

The content of the message.

dm

A boolean which defines whether the message is a DM or not.

Functions

isDM

message.isDM() : boolean;

Returns a boolean which defines whether the message is a DM or not.

delete

message.delete() : Promise<void>;

Deletes the message. The function returns a Promise which gets fulfilled once the message has been deleted.

reply

message.reply(...content: [string, Embed, ActionRowBuilder, ButtonBuilder, SelectMenuBuilder, object]) : Promise<Message>;

Sends a reply to the message. The function returns a Promise which returns an instance of the Message class once the reply has been sent.

ArgumentDescription

content

The content of the message the bot should send. The content must be a string, an Embed class, the ActionRowBuilder class, the ButtonBuilder class, the SelectMenuBuilder class or an object which provides the message its content.

The object of the message may contain the following information:

  • content: A string of the content of the message.

  • embeds: An array with the Embed class.

  • files: An array with a string which represents a file url or an object when uploading a file.

  • components: An array with the Discord.js ActionRowBuilder class.

The file object data may contain the following information:

  • name: The name of the file you want to upload

  • attachment: The path of the file you want to upload

  • description: The description of the file

edit

message.edit(...content: [string, Embed, ActionRowBuilder, ButtonBuilder, SelectMenuBuilder, object]) : Promise<Message>;

Edits the message when the message is editable. The function returns a Promise which returns an instance of the Message class once the message has been edited.

ArgumentDescription

content

The content of the message the bot should edit. The content must be a string, an Embed class, the ActionRowBuilder class, the ButtonBuilder class, the SelectMenuBuilder class or an object which provides the message its content.

The object of the message may contain the following information:

  • content: A string of the content of the message.

  • embeds: An array with the Embed class.

  • files: An array with a string which represents a file url or an object when uploading a file.

  • components: An array with the Discord.js ActionRowBuilder class.

The file object data may contain the following information:

  • name: The name of the file you want to upload

  • attachment: The path of the file you want to upload

  • description: The description of the file

react

message.react(reaction: Emoji | string) : Promise<Message>;

Reacts to the message with an emoji. The function returns a Promise which returns an instance of the Message class with the updated data once the reaction has been added.

ArgumentDescription

reaction

An instance of the Emoji class or a string which represents an emoji where the bot should react with.

removeAttachments

message.removeAttachments() : Promise<Message>;

Removes the attachments added to the message. The function returns a Promise which returns an instance of the Message class with the updated data once the attachments have been removed.

update

message.update() : Promise<Message>;

Updates the message in case there were made changes to it which weren't noticed by the Discord WebSocket connection. The function returns a Promise which returns an instance of the Message class with the updated data once the message has been updated.

createThread

message.createThread(options: object) : Promise<ThreadChannel>;

Creates a thread channel based on the message. The function returns a Promise which returns an instance of the ThreadChannel class which represents the thread channel created for the message once the thread channel has been created. This can only be used for text channels.

ArgumentDescription

options

An object with the data for the new thread channel.

The options object may contain the following information:

  • name: The name you'd like to give the thread channel.

  • reason: The reason you'd like to create a thread channel. This must be a string between 1-512 characters.

  • autoArchiveThread: The time it takes before thread channel automatically archives after inactivity. This must be a number which defines the time in miliseconds, an instance of the Date class where the timestamp gets substracted of the current timestamp and the difference is used as the auto archive duration or a string which defines the time like 1 hour. The duration must be an hour, a day, 3 days or a week.

  • slowMode: The time the users have to wait before they can send another message after sending a message in the new thread channel. This must be a number which defines the time in miliseconds, an instance of the Date class where the timestamp gets substracted of the current timestamp and the difference is used as the slow mode time or a string which defines the time like 1 hour.

executeCommand

message.executeCommand(commandName: string, args?: [any]) : Promise<void>;

Executes another registered command based on the message sent by the member. The command can be a default Zyno Bot command or another command created by another addon.

ArgumentDescription

commandName

The name of the command you'd like to execute. The information provided in the current message, such as the channel or member, will also be provided to the command which you'd like to execute.

args

An array of custom arguments. The command will be based on the custom arguments instead of the arguments provided in the sent message by the member.

createReactionCollector

message.createReactionCollector(options: object) : EmojiCollector;

Creates a collector which will collect reactions reacted on the current message. The reactions must meet the criteria set in the options argument. The function will return an instance of the EmojiCollector class.

ArgumentDescription

options

An object with information how the collector should be created.

The options object may contain the following information:

  • max: The maximum amount of reactions the collector should collect. After reaching this maximum, the collector will stop collecting reactions.

  • time: The amount of milliseconds the collector should work. After this time has passed, the collector will stop collecting reactions.

  • filter: A function with two parameters, a Reaction class and a User class, and should return a boolean. The function will be used to check if a reaction meets certain requirements set in this function. If so, the reaction will be collected.

createInteractionCollector

message.createInteractionCollector(options: object) : EmojiCollector;

Creates a collector which will collect interactions on the current message. The interactions must meet the criteria set in the options argument. The function will return an instance of the InteractionCollector class.

ArgumentDescription

options

An object with information how the collector should be created.

The options object may contain the following information:

  • max: The maximum amount of interactions the collector should collect. After reaching this maximum, the collector will stop collecting interactions.

  • time: The amount of milliseconds the collector should work. After this time has passed, the collector will stop collecting interactions.

  • filter: A function with one parameters, a ButtonInteraction class or a MenuInteraction class, and should return a boolean. The function will be used to check if an interaction meets certain requirements set in this function. If so, the interaction will be collected.

Last updated