I would like to have a discord bot reply to a message made in a public channel via a private message.
I am able to detect whether a channel is private or not using the following code from the FAQ:
func isTheChannelTheMessageWasSentInPrivate(s *discordgo.Session, m *discordgo.MessageCreate) {
channel, err := s.State.Channel(m.ChannelID)
if err != nil {
astilog.Fatal(err)
return
} else if m.Author.ID == s.State.User.ID {
return
}
channelIsPrivate := strconv.FormatBool(channel.IsPrivate)
print("Channel ID: " + m.ChannelID + ". Is it private? " + channelIsPrivate + "\n")
}
And I can reply to a message on the same channel it was received using this code:
func recieveMessage(s *discordgo.Session, m *discordgo.MessageCreate) {
s.ChannelMessageSend(m.ChannelID, "Reply!")
}
But I can't figure our how to get the ChannelID
of a user's direct message channel from the Message
object that is available upon receiving a message.
Assuming you, and the other user are in the same server, this should be relatively simple. Open the Discord Channel and tap on their profile icon. A small box will appear letting you type a private message. Simple. Now, this only works if you both are in the same groups.
A page will appear with a shareable link. Copy and paste it in a text or message (on another platform) send it to the person you’d like to chat with. If they click the link and accept you can private message them as we explained above, or chat with them in your Discord channel.
One of the great features that Discord has to offer is the ability to chat without trolls, spam, and just plain excessively annoying discourse. With that said, one of the drawbacks is the ability to message anyone you’d like whenever you’d like. Officially, Discord doesn’t give us the option to chat with another user unless we’re friends.
If someone has been sending you unsolicited messages on Discord, you can make use of the block feature to keep them from continuing to do so. After you block them, they won’t be able to send you messages or friend requests until you unblock them.
The session struct has a method UserChannelCreate(recipientID string)
, which returns the DM channel for given userID. Don't mind the 'Create', if a DM channel already exists, it will be reused.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With