【问题标题】:TypeError: message.guild.channels.find is not a function discord.js [duplicate]TypeError:message.guild.channels.find 不是函数 discord.js [重复]
【发布时间】:2020-09-03 18:50:42
【问题描述】:

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

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

【问题讨论】:

标签: javascript node.js typeerror discord.js


【解决方案1】:

已更新。尝试使用:

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

ticketChannel.send(ticketEmbed)

希望这会有所帮助!

【讨论】:

  • 添加 .cache.find 时,它给了我另一个错误:/Users/scribblenerd/Documents/Discord Bots/Discord.js/raokapp-discord-ticket-bot/node_modules/@discordjs/collection/ dist/index.js:158 fn = fn.bind(thisArg); ^ TypeError: fn.bind 不是函数
  • (这是一个 imgur,因为 cmets 中没有任何文本格式:imgur.com/a/loOCDQK
  • 您必须使用message.guild.channels.cache.find(channel => channel.name === 'channelName') 之类的操作,其中 channelName 是频道名称
  • 现在它在“ticketChannel.send(ticketEmbed)”上给我“无法读取未定义的属性‘发送’”
  • 对不起,再次检查我的答案,很快就会更新它
猜你喜欢
  • 2021-01-13
  • 2020-09-02
  • 2021-02-18
  • 2022-01-17
  • 2020-12-31
  • 2020-12-07
  • 2020-08-23
  • 2020-01-22
  • 2020-11-13
相关资源
最近更新 更多