Comment on page
On Discord Private Message
On Discord Private Messageblocks are event blocks that fire whenever a specified Discord account or Discord bot receives a private Discord message.
On Discord Private Messageblocks only have one input: a Discord connection that must be provided by a
Discord Connectorblock. The Discord account or bot token that is provided to the
Discord Connectorwe use will determine which account or bot our
On Discord Private Messageblock will be listening to private messages for.
On Discord Private Messageblocks output several pieces of data:
-A string called "From" which will be equal to the Discord username of the message sender. -A string called "Message" which will be equal to the contents of the private message. -An integer called "MessageId" which is an identifier for the message we have received. This can be used as input for any block type that requires a reference to a message, like
On Reaction Added Messageblocks. -A variable called "Author", which is a reference to the Discord account that sent the private message. This is used specifically to plug into the "Author" input of
Reply Private Discord Messageblocks, in order to indicate which Discord user it should be replying to.
In the following example, whenever our Discord bot receives a private message, we detect it with our
On Discord Private Messageblock, and then send it to a
String Branchblock to check if the message equals "good bot". If it does, then we use a
Reply Private Discord Messageblock to send a thank-you message back to the user who sent the "good bot" message.
Note that the "Author" output of the
On Discord Private Messageblock is plugged into the
Reply Private Discord Messageblock to indicate that the reply should be made to the same user that sent the original private message.
In this example, our thank-you message is customized to include the username of the Discord user who sent the original private message. We achieve this by constructing our message with a
Replace String In Stringblock, and feeding the "From" output of our
On Discord Private Messageblock into the "ReplaceText" input of the
Replace String In Stringblock.