đŦManaging messages
How to create a message?
Accessing from the Client the method is create a message is pretty simple and straightforward.
You can also access it using various helper methods provided by the library (aka shortcut methods):
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 bot
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.
E.g:
I send the message 'hello'
It detects the message hello
Sends a message with content 'a message has been sent!'
Detects if the content is hello, if it is, it sends a message with content: hello
Detects a message 'hello'
... loops .. and so on..
OUTPUT (chat channel):
a message has been sent!
hello
a message has been sent!
hello
... and so on..
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.bot 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'
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 bot.
1. Storing new messages.
2. Using editLast
This method called editLast was previously editLastMessage in older TouchGuild versions
Last updated