繁体   English   中英

channel.send 不是 function discord.js

[英]channel.send is not a function discord.js

我正在发出反馈命令,我想在特定通道中记录反馈,但出现此错误: UnhandledPromiseRejectionWarning: TypeError: channel.send is not a function

代码:

const { DiscordAPIError } = require("discord.js");
const Discord = require('discord.js');
const client = new Discord.Client();

module.exports = {
    name: "feedback",
    description: "Send your feedback for the bot!",
    async execute(message, args) {
        const feedback = args.slice(0).join(" ");
        const no_feedback = new Discord.MessageEmbed()
        .setColor("#993333")
        .setTitle("Feedback")
        .setDescription("An error has occured.")
        .addField("Error" , "You didn't type your feedback after the command!")
        .addField("What to do?" , "Type `=feedback` and add your feedback right after.")
        .setFooter(message.author.username)
        .setTimestamp();

        const confirm = new Discord.MessageEmbed()
        .setColor("#993333")
        .setTitle("Confirm")
        .setDescription("Trolling can result in a ban!")
        .addField("Feedback" , `Your feedback will be shown as \n **${feedback}**`)
        .setFooter(message.author.username)
        .setTimestamp();

        if(!feedback) return message.reply(no_feedback);

        const confirmation = await message.channel.send(confirm);
        const emojis = ['✅', '❌'];

        emojis.forEach((emoji) => confirmation.react(emoji));

        const filter = (reaction, user) =>
  user.id === message.author.id && emojis.includes(reaction.emoji.name);

const collector = confirmation.createReactionCollector(filter, { max: 1 });

collector.on('collect', (reaction, user) => {
  const [confirm, cancel] = emojis;

  confirmation.delete();

  if (reaction.emoji.name === cancel) {
    const cancelEmbed = new Discord.MessageEmbed()
      .setColor('#993333')
      .setTitle('Cancelled')
      .setDescription(
        `Cancelled! The feedback has not been sent.`,
      )
      .setFooter(message.author.username)
      .setTimestamp();
    return message.channel.send(cancelEmbed);
  }

  if (reaction.emoji.name === confirm) {
    const bannedEmbed = new Discord.MessageEmbed()
      .setColor('#993333')
      .setTitle('Sent')
      .setDescription(
        `Your feedback has been sent!`,
      )
      .setFooter(message.author.username)
      .setTimestamp();
    message.channel.send(bannedEmbed);
    const feedback_admins = new Discord.MessageEmbed()
    .setColor('#993333')
      .setTitle('Feedback')
      .setDescription(
        `We have gotten feedback!`,
      )
      .addFields(
          {name:"From" , value: message.author.username} ,
          {name:"In" , value: message.guild.name} ,
          {name:"Feedback" , value: feedback} ,
          )
      .setFooter(message.author.username)
      .setTimestamp();
      const channel_id = client.channels.cache.find((channel) => {
        return channel.id === "816714319172599828";
     });
     
     channel_id.send(feedback_admins);
  }
});
    }
}

编辑:现在发布完整的代码,我希望这样可以,因为我已经得到了答案。 错误不再相同:现在是:类型错误。 无法读取未定义的属性发送,错误消息说错误在第 83 行。所以 channel_id.send(feedback_admins)。

也许频道没有被缓存。 尝试使用fetch代替:

const channel = await client.channels.fetch('816714319172599828');
channel.send(feedback_admins);

PS:您的第一个错误是TypeError: channel.send is not a function ,所以它似乎不是文本通道。

你可以使用这样的东西。

// to get the channel
const channel_id = client.channels.cache.find((channel) => {
   return channel.id === "816714319172599828";
});

channel_id.send(feedback_admins);

我找到了答案,看来我不得不使用message.guild.channels.cache.get("816714319172599828")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM