簡體   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