πŸ“¬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.

client.rest.channels.createMessage(channelID, options);
client.createMessage(channelID, options);
// e.g:
client.rest.channels.createMessage("abcd-12345", { content: "hi!" });
client.createMessage("abcd-12345", { content: "hi!" });

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.

Message.createMessage(options); // acknowledges and reply to the 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

circle-info

We're shipping TouchGuild with a wide range of events, you can check them out here.arrow-up-right

Create a message when someone says 'hi'

Another way to do that without storing the message 'member'

Common mistakes

triangle-exclamation
triangle-exclamation

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

circle-info

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

Was this helpful?