【发布时间】:2018-09-17 22:11:31
【问题描述】:
我想让 Discord 机器人通过私人消息回复在公共频道中发送的消息。
我可以使用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")
}
我可以使用此代码在收到消息的同一频道上回复消息:
func recieveMessage(s *discordgo.Session, m *discordgo.MessageCreate) {
s.ChannelMessageSend(m.ChannelID, "Reply!")
}
但我不知道如何从收到消息时可用的Message 对象获取用户直接消息通道的ChannelID。
【问题讨论】:
-
我认为这有点令人困惑,也许只是我。您似乎已经知道如何从 Message 对象中获取 ChannelID。
Message.ChannelID -
Message.ChannelID是发送消息的公共频道。我想回复发消息的用户的私人频道。