我想通过私人消息对公共频道中的消息进行不和谐机器人回复.
我可以使用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")
}
Run Code Online (Sandbox Code Playgroud)
我可以使用以下代码回复收到的同一频道上的消息:
func recieveMessage(s *discordgo.Session, m *discordgo.MessageCreate) {
s.ChannelMessageSend(m.ChannelID, "Reply!")
}
Run Code Online (Sandbox Code Playgroud)
但我无法想象如何ChannelID从Message接收消息时可用的对象获取用户的直接消息通道.
会话结构有一个方法UserChannelCreate(recipientID string),它返回给定用户 ID 的 DM 频道。不要介意“创建”,如果 DM 频道已经存在,它将被重用。
| 归档时间: |
|
| 查看次数: |
983 次 |
| 最近记录: |