【问题标题】:Send private message with discordgo使用 discordgo 发送私信
【发布时间】: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 是发送消息的公共频道。我想回复发消息的用户的私人频道。

标签: go discord


【解决方案1】:

会话结构有一个方法UserChannelCreate(recipientID string),它返回给定用户ID 的DM 通道。不要介意“创建”,如果 DM 频道已经存在,它将被重复使用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-05
    • 2019-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-01
    • 2013-01-26
    • 1970-01-01
    相关资源
    最近更新 更多