首页 文章

使用discordgo发送私信

提问于
浏览
6

我希望通过私人消息对公共 Channels 中的消息进行不和谐机器人回复 .

我可以使用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")
}

我可以使用此代码回复收到的同一 Channels 上的消息:

func recieveMessage(s *discordgo.Session, m *discordgo.MessageCreate) {
    s.ChannelMessageSend(m.ChannelID, "Reply!")
}

但我无法想象如何从收到消息时可用的Message对象获取用户直接消息通道的 ChannelID .

1 回答

  • 3

    session结构有一个方法 UserChannelCreate(recipientID string) ,它返回给定userID的DM通道 . Don 't mind the '创建',如果DM通道已经存在,它将被重用 .

相关问题