【问题标题】:How would I make an announcement go to the mentioned channel?我将如何在提到的频道上发布公告?
【发布时间】:2019-03-08 22:51:36
【问题描述】:

我该怎么做才能让你说;announce #channel message?所以不是在你写消息的频道中发送它,而是将它发送到你提到的频道?

if (message.content.toLowerCase().startsWith(prefix + `announce`)) {
  if (message.member.hasPermission("ADMINISTRATOR")) {
    let args = message.content.split(" ").slice(1).join(" ");
    let split = args.split("-");
    let url = args[2];
    message.channel.sendMessage("@everyone", {
      embed: {
        color: 0xFFFF00,
        title: "New Announcement!",
        description: split[0],
        url: split[1],
        timestamp: new Date(),
        footer: {
          icon_url: message.author.avatarURL,
          text: message.author.username
        }
      }
    });
  }
}

【问题讨论】:

    标签: javascript node.js discord discord.js


    【解决方案1】:

    Message.mentions 包含消息中的每个提及,其属性.channels 为您提供提及的每个频道。
    知道您可以从提及中获取频道,然后将其从参数中删除。

    这是一个例子:

    if (message.content.toLowerCase().startsWith(prefix + `announce`)) {
      if (message.member.hasPermission("ADMINISTRATOR")) {
        // I've added this part
        let channel = message.mentions.channels.first(); // you get the first mentioned channel
        if (!channel) return message.reply("No channel mentioned."); // if it doesn't exist, you exit
        let args = message.content.split(" ").slice(2).join(" "); // if it exist, you remove the command AND the channel
    
        let split = args.split("-");
        let url = args[2];
        channel.sendMessage("@everyone", { // here you send it to your channel instead of the same one
          embed: {
            color: 0xFFFF00,
            title: "New Announcement!",
            description: split[0],
            url: split[1],
            timestamp: new Date(),
            footer: {
              icon_url: message.author.avatarURL,
              text: message.author.username
            }
          }
        });
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-28
      • 2015-02-13
      • 2021-05-28
      • 2021-10-02
      • 1970-01-01
      • 1970-01-01
      • 2019-05-05
      • 2019-12-27
      相关资源
      最近更新 更多