首页 > 解决方案 > TypeError:message.guild.channels.find 不是函数 discord.js

问题描述

以下代码在标题中产生错误:

message.guild.channels.create("ticket-" + data.ticketCounter, 
{
  type: 'text',
  parent: '702634860363382784',
  permissionOverwrites: [
    {
      id: message.guild.id,
      deny: ['VIEW_CHANNEL']
    },
    {
      id: message.author.id,
      allow: ['SEND_MESSAGES', 'VIEW_CHANNEL', 'ADD_REACTIONS', 'EMBED_LINKS', 'ATTACH_FILES', 'READ_MESSAGE_HISTORY', 'USE_EXTERNAL_EMOJIS']
    },
    {
      id: "702701257290154044",
      allow: ['SEND_MESSAGES', 'VIEW_CHANNEL', 'ADD_REACTIONS', 'EMBED_LINKS', 'ATTACH_FILES', 'READ_MESSAGE_HISTORY', 'USE_EXTERNAL_EMOJIS']
    }
  ]
})

const ticketEmbed = new Discord.MessageEmbed()
  .setColor(config.embedColor)
  .setTitle('New ticket from ' + message.author.tag)
  .setDescription(messageContent.join(" "))

const ticketChannel = message.guild.channels.find('name', `ticket-${data.ticketChannel}`);
ticketChannel.send(ticketEmbed)

我已经看过这篇文章:  TypeError: message.guild.channels.find(...).then is not a function并且正在使用其中的代码,但我仍然收到错误消息。我在 Discord.js 版本 12.2.0、node.js 版本 12.16.1 和 npm 版本 6.14.4

标签: javascriptnode.jstypeerrordiscord.js

解决方案


它已更新。尝试使用:

const ticketChannel = message.guild.channels.cache.find(channel => channel.name === 'channelName') 

ticketChannel.send(ticketEmbed)

希望这可以帮助!


推荐阅读