无法读取未定义的 discord.js 的“频道”的属性

时间:2021-05-09 21:47:47

标签: javascript discord discord.js

const reason = args.slice(0).join(" ");
    if (!reason) return message.channel.send('Reason for ticket?');
const user =  message.guild.member(message.author);
 const ticket = db.fetch(`Ticket_user_${user.id}`)
if(ticket) message.channel.send("You already made a ticket senpai! Close your old ticket.");
 const channel = message.guild.channels.cache.find
        (channel => channel.name === 'ticket')
      if (!channel)
guild.channels.create('ticket', {
    type: 'text',
    permissionOverwrites: [
        {
            id: message.guild.id,
            deny: ['VIEW_CHANNEL'],
        },
        {
            id: message.author.id,
            allow: ['VIEW_CHANNEL'],
        },
    ],
})
  .then(console.log)
  .catch(err => {
   message.channel.send("An error occurred while running the command. Please report this error to the support server:"+ err)
  return;
})
 db.add(`Ticket_user_${user.id}`)
const time = "3"
 setTimeout(() => {
   const embed = new Discord.MessageEmbed()
      .setTitle(`Ticket#0001`)
      .setDescription(`Reason: ${reason}`)
      .addField("Welcome to my ticket senpai!! We are waiting for staff")
      .setColor("PURPLE")
message.channel.send(embed)
    }, ms(time))
}
}

我正在为我的机器人制作一个票务系统,希望你们聪明,因为 top.gg 没有帮助 谢谢你的帮助,这将帮助我的机器人和我的代码,让我变得聪明,而且我正在删除点因为 downvote ig

1 个答案:

答案 0 :(得分:0)

在这段代码中

if (!channel){
    guild.channels.create('ticket', { //...... rest of the code

您没有定义 guild。尝试用 guild
替换 message.guild 像这样:

if (!channel){
message.guild.channels.create('ticket', { //.... rest of the code

另外,请删除问题中不需要的部分(点)