如何向所有服务器公开建议命令?不和谐.js

时间:2021-06-04 14:00:31

标签: discord discord.js

我的机器人上有一个我正在处理的建议命令。然而,它仅在用户建议在我的服务器中时才有效,因为它被编码为将建议发送到特定的频道 ID。即使用户建议不在服务器中,有没有办法在建议出现在我的 dms 或指定频道的地方对其进行编码?这是我的代码:

const { MessageEmbed } = require("discord.js")

module.exports.run = async (client, message, args) => {
  if (!args.length) {
    return message.channel.send("Please Give the Suggestion")
  }

  let channel = message.guild.channels.cache.find((x) => (x.name === "sauce-supplier-suggestions" || x.name === "sauce-supplier-suggestions"))

  if (!channel) {
    return message.channel.send("there is no channel with name - sauce-supplier-suggestions")
  }

  let embed = new MessageEmbed()
    .setAuthor("SUGGESTION: " + message.author.tag, message.author.avatarURL())
    .setThumbnail(message.author.avatarURL())
    .setColor("#ff2050")
    .setDescription(args.join(" "))
    .setTimestamp()

  channel.send(embed).then(m => {
    m.react("✅")
    m.react("❌")
  })
  message.channel.send("sucsessfully sent your suggestion to bot team thank you for your suggestion!!")
}

1 个答案:

答案 0 :(得分:0)

我对您的代码做了一些小改动。现在,如果用户正确使用该命令,机器人将向您发送包含用户建议的 DM。

const { MessageEmbed } = require("discord.js")

module.exports.run = async (client, message, args) => {
  let suggestion = args.join(" ");
  let owner = client.users.cache.get("YOUR ID");

  if (!suggestion) {
    return message.channel.send("Please Give the Suggestion")
  }

  let channel = message.guild.channels.cache.find((x) => (x.name === "sauce-supplier-suggestions" || x.name === "sauce-supplier-suggestions"))

  if (!channel) {
    return message.channel.send("there is no channel with name - sauce-supplier-suggestions")
  }

  let embed = new MessageEmbed()
    .setAuthor("SUGGESTION: " + message.author.tag, message.author.displayAvatarURL({ dynamic: true }))
    .setThumbnail(message.author.displayAvatarURL({ dynamic: true }))
    .setColor("#ff2050")
    .setDescription(suggestion)
    .setTimestamp()

  owner.send(embed).then(m => {
    m.react("✅")
    m.react("❌")
  })
  message.channel.send("sucsessfully sent your suggestion to bot team thank you for your suggestion!!")
}