JavaScript discord bot TypeError:无法读取未定义的属性“公会”

时间:2021-07-02 17:13:56

标签: discord.js

我正在我的不和谐机器人中尝试这个 JavaScript 票证代码,但错误 TypeError: Cannot read property 'guild' of undefined 不断出现。我不明白为什么。有人能指导我正确的方向吗?

module.exports = {
    name: "ticket",
    aliases: [],
    permissions: [],
    description: "Open a ticket!",
    async execute(message, args, cmd, client, discord) {
      const channel = await message.guild.channels.create(`ticket: ${message.author.tag}`);
      channel.setParent("820276801652916270");
  
      channel.updateOverwrite(message.guild.id, {
        SEND_MESSAGE: false,
        VIEW_CHANNEL: false,
      });
      channel.updateOverwrite(message.author, {
        SEND_MESSAGE: true,
        VIEW_CHANNEL: true,
      });
  
      const reactionMessage = await channel.send("Thank you for contacting support!");
  
      try {
        await reactionMessage.react("?");
        await reactionMessage.react("⛔");
      } catch (err) {
        channel.send("Error sending emojis!");
        throw err;
      }
  
      const collector = reactionMessage.createReactionCollector(
        (reaction, user) => message.guild.members.cache.find((member) => member.id === user.id).hasPermission("ADMINISTRATOR"),
        { dispose: true }
      );
  
      collector.on("collect", (reaction, user) => {
        switch (reaction.emoji.name) {
          case "?":
            channel.updateOverwrite(message.author, { SEND_MESSAGES: false });
            break;
          case "⛔":
            channel.send("Deleting this channel in 5 seconds!");
            setTimeout(() => channel.delete(), 5000);
            break;
        }
      });
  
      message.channel
        .send(`We will be right with you! ${channel}`)
        .then((msg) => {
          setTimeout(() => msg.delete(), 7000);
          setTimeout(() => message.delete(), 3000);
        })
        .catch((err) => {
          throw err;
        });
    },
}

1 个答案:

答案 0 :(得分:1)

使用您评论中的信息,您的命令处理程序设置不正确。当您输入 execute(message.args) 时,代码尝试传递返回 args 的消息参数的 undefined 属性。

相反,您应该使用 execute(message, args) 为您的命令正确传递每个参数。