đŦManaging messages
How to create a message?
Using REST methods
Accessing from the Client the method is create a message is pretty simple and straightforward.
Using the Message itself
The main differences between creating a message with the message itself rather than using REST, are that it is faster, and behaves differently: it replies to it.
createMessage â Reply to the trigger message.
By replying to the trigger message, which is the message that triggers your application, that is most likely sent by a user: it creates an original response to it and acknowledges your message.
createFollowup
Send a follow-up message that replies to the original response, the current Message has to be acknowledged to be used.
How do I detect when a message is created, edited or deleted?
We use client.on to detect when an event is triggered.
Detect when a message is created
Detect when a message is edited
Detect when a message is deleted
We're shipping TouchGuild with a wide range of events, you can check them out here.
Create a message when someone says 'hi'
Another way to do that without storing the message 'member'
Common mistakes
Not adding the condition to return in case the user that sent the message is a app
Yes, it is a fairly common mistake among beginners, by not putting this condition and send a message whatever the message is, this can cause sooner or later a creation of a bunch of messages in a short period of time.
In this case, we're detecting if the message content is 'hi', which makes it unable to loop, but it could happen by running messageCreate outside the condition.
Using message.member directly without awaiting it
message.member is a getter method that returns a Promise, you have to await it to be able to access to its properties, in that case message.member.app will be undefined instead of a boolean.
OUTPUT (console):
and don't forget to make the function asynchronous (async) if you're using await inside it!
Replying to a message
The difference with creating a message and replying, is that the reply mentions the user, and links the new message to a 'replied message'
Though replying is already built-in the Message component methods, you can still
It is very similar to creating a message, you only add the property replyMessageIds
Logging things to a specific channel
Deleting messages containing swear words
Editing messages
There's different ways to edit messages sent by the app.
1. Storing new messages.
2. Using editLast
This method called editLast was previously editLastMessage in older TouchGuild versions
2. Using editOriginal
2. Using editFollowup
A derivative of editLast, that only works on followups.
Last updated