【问题标题】:JDA - Send message to specific channelJDA - 向特定频道发送消息
【发布时间】:2020-07-02 11:56:05
【问题描述】:

我目前正在使用 Java 和 jda 制作一个不和谐的机器人。我想让机器人向特定频道发送消息。我该怎么做?

【问题讨论】:

    标签: discord-jda


    【解决方案1】:

    该问题已在 StackOverFlow 社区中提出。

    如果你在 StackOverFlow 中搜索它,你会找到 this Question

    这是简单的答案! ;)

    TextChannel textChannel = event.getGuild().getTextChannelsByName("CHANNEL_NAME",true).get(0);
    textChannel.sendMessage("MESSAGE").queue();
    

    【讨论】:

      【解决方案2】:

      您可以像这样通过 ID 获取频道:

      TextChannel txtChannel = event.getJDA().getTextChannelById("348110542667251712");
      
      if (txtChannel.canTalk()) {
          txtChannel.sendMessage("Your message here.").queue();
      }
      

      使用您可以验证的.canTalk() 方法,机器人有权在该频道中读取和发送消息。

      【讨论】:

        猜你喜欢
        • 2019-03-01
        • 2021-08-21
        • 2020-04-04
        • 2018-12-09
        • 2022-01-08
        • 2021-01-26
        • 2021-01-01
        • 2020-10-01
        相关资源
        最近更新 更多